nginx 日誌主要有兩條指令:
- log_format:用來設置日誌格式;
- access_log:用來指定日誌文件的存放路徑、格式(把定義的log_format
跟在後面)和緩存大小;如果不想啓用日誌則access_log off ;
log_format 日誌格式
- 語法:
log_format name(格式名字) 格式樣式(即想要得到什麼樣的日誌內容)
示例:
log_format main
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_s ent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
- 具體可設置的參數格式及說明如下:
access_log
用了log_format 指令設置了日誌格式之後,需要用access_log指令指定日誌文件的存放路徑;
語法 :access_log path(存放路徑) format (自定義日誌名稱)
示例 : access_log logs/access.log main;