今天學習了nginx 的日誌切換,
在配置文件nginx.conf中
http{
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server{
access_log logs/mylog.conf mylogformat
location / {
}
}
}
access_log 表示日誌文件 後面加日誌格式 (當更改了日誌格式,重新加載配置文件時,不會更改格式,這時必須切換一個新的文件纔可以 )
log_format 表示日誌格式 (要定義 在http 下面, 一開始我放在了server中, 錯誤了)
$remote_addr 客戶端地址, 當nginx作爲Web服務器時,使用反向代理Squid,nginx 等訪問web服務器時,這個值是錯誤的,總是獲取到代理服務器的地址。這時有一個頭部屬性來記錄真正客戶端的地址,$http_x_forwarded_for 。
$remote_user 遠程客戶端用戶名稱
$request 請求的URL
$status 服務器返回的狀態(404 304 505 500)
$body_bytes_sent 返回的字節數
$http_referer 記錄從哪個網頁鏈接過來的
$http_user_agent 客戶端瀏覽器(Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36)