Nginx不记录指定文件类型的日志
Nginx默认日志记录太详细,包括了很多图片等信息,如何设置不记录指定文件的类型的日志呢?
一、设置Nginx日志类型
日志格式类型:daixuan 远程的IP,代理IP,时间,域名,访问地址,链接,状态码,referer,浏览器信息
[root@daixuan conf]# cd /usr/local/nginx/conf/
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format daixuan ‘$remote_addr $http_x_forwarded_for [$time_local]‘
‘$host "$request_uri" $status‘
‘"$http_referer" "$http_user_agent"‘;
......
}
二、修改虚拟主机配置文件,使用指定的类型的日志
[root@daixuan conf]# cd vhosts/
[root@daixuan vhosts]# vim test.conf
server
{
listen 80;
server_name www.test.com www.aaa.com www.bbb.com;
if ($host != ‘www.test.com‘){
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log daixuan; //添加日志格式类型为daixuan的日志
location ~ .*admin\.php$ {
auth_basic "daixuan auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
access_log off;
}
location ~ (static|cache) {
access_log off;
}
}
[root@daixuan vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
三、测试日志文件,日志中包括很多jpg、png、static、cache的日志都没有记录
[root@daixuan vhosts]# cat /tmp/access.log
本文出自 “daixuan” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1734360
原文地址:http://daixuan.blog.51cto.com/5426657/1734360