1. 檢視主配置檔案定義的日志格式 /usr/local/nginx/conf/nginx.conf
日志格式說明:
combined_realip #表示日志格式名稱,可自定義
remote_addr #表示遠端主機
http_x_forwarded_for #表示代理ip
time_local #表示時間
host #表示域名
request_uri #表示通路的位址
status #狀态碼
http_referer #表示referer
http_user_agent #表示使用者代理資訊
<code>log_format combined_realip </code><code>'$remote_addr $http_x_forwarded_for [$time_local]'</code> <code>'$host "$request_uri" $status'</code> <code>'"$http_referer" "$http_user_agent"'</code><code>;</code>
2. 編輯虛拟主機配置檔案 /usr/local/nginx/conf/vhosts/huangzhenping.conf
說明:添加日志配置;用location比對并過濾檔案類型,如有多個location且内容有交集,按先後順序執行
加入:
<code>access_log </code><code>/tmp/access</code><code>.log combined_realip;</code>
<code> </code><code>location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {</code>
<code> </code><code>access_log off;</code>
<code> </code><code>}</code>
<code> </code><code>location ~ (static|cache)</code>
<code> </code><code>{</code>
<code> </code><code>access_log off;</code>
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
本文轉自 huangzp168 51CTO部落格,原文連結:http://blog.51cto.com/huangzp/1900637,如需轉載請自行聯系原作者