您的位置:首页 > 运维架构 > Nginx

LNMP--Nginx不记录指定文件日志

2015-08-12 10:01 561 查看
编辑Nginx配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/nginx.conf
找到下面一行:
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
将内容更改为:
log_format linan '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在 “root /data/www” 下面写入:

access_log /tmp/access.log linan; (红字用户名对应上面更改后的用户名)
检查并重加载:
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,我们查看日志:
[root@LampLinux ~]# cat /tmp/access.log
发现记录了很多内容,其中图片信息没有必要去记录。
配置不记录指定文件日志:

编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在"用户认证"配置下面写入:
location ~ .*\.(gif|jpg|png|jpeg|bmp|swf)$
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,继续查看日志:
[root@LampLinux ~]# cat /tmp/access.log

发现没有限制记录的图片了,但是还有js和css类型的图片没有禁止记录。
下面我们去配置,还是进入“虚拟主机配置文件”编辑,在上一段下面继续补充一段:
location ~ (static|cache) # 限定static和cache,因为日志中观察到css和js都在这个目录下。
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,查看日志:
[root@LampLinux ~]# cat /tmp/access.log
不记录限制的图片文件了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  记录 配置文件