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 #表示用户代理信息
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' '$host "$request_uri" $status' '"$http_referer" "$http_user_agent"';
2. 编辑虚拟主机配置文件 /usr/local/nginx/conf/vhosts/huangzhenping.conf
说明:添加日志配置;用location匹配并过滤文件类型,如有多个location且内容有交集,按先后顺序执行
加入:
access_log /tmp/access.log combined_realip; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { access_log off; } location ~ (static|cache) { access_log off; }
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
转载于:https://blog.51cto.com/huangzp/1900637