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

LNMP搭建8:Nginx不记录指定文件类型日志

2017-02-25 12:50 375 查看
在Nginx主配置文件中
[root@cp1 conf]# vim nginx.conf
有关于日志的格式定义如下:



在虚拟主机配置文件中选择日志格式类型定义我们的日志
[root@cp1 conf]# vim vhosts/test.conf
定义访问日志的存放路径和格式



重新加载配置文件:
[root@cp1 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 conf]# /usr/local/nginx/sbin/nginx -s reload
访问几次
[root@cp1 conf]# curl -x127.0.0.1:80 www.test.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Thu, 23 Feb 2017 16:39:25 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
location: forum.php
[root@cp1 conf]# curl -x127.0.0.1:80 www.test.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Thu, 23 Feb 2017 16:39:30 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
location: forum.php
查看产生的日志
[root@cp1 conf]# ls /tmp/access.log
/tmp/access.log
[root@cp1 conf]# cat /tmp/access.log
127.0.0.1 - [24/Feb/2017:00:39:25 +0800]www.test.com "/" 301"-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
127.0.0.1 - [24/Feb/2017:00:39:30 +0800]www.test.com "/" 301"-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
刷新浏览器之后
[root@cp1 conf]# cat /tmp/access.log



编辑虚拟主机配置文件,设置指定文件类型的访问不记入日志
[root@cp1 conf]# vim vhosts/test.conf



检查错误重启服务
[root@cp1 conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 conf]# /usr/local/nginx/sbin/nginx -s reload
先清空日志
[root@cp1 conf]# > /tmp/access.log
刷新浏览器后指定文件类型的访问不记录


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  搭建 Nginx LNMP