日志格式
vim /usr/local/nginx/conf/nginx.conf //搜索log_format
combined_realip //规则名字
vim /usr/local/nginx/conf/vhost/test.com.conf
添加 access_log /tmp/1.log combined_realip;
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl -x127.0.0.1:80 test.com -I
cat /tmp/1.log
vim /usr/local/sbin/nginx_log_rotate.sh //写入如下内容
#! /bin/bash
d=`date -d "-1 day" +%Y%m%d`
logdir="/tmp/"
nginx_pid="/usr/local/nginx/logs/nginx.pid"
cd $logdir
for log in `ls *.log` //for后面的log是一个变量名,
do
mv $log $log-$d
done
/bin/kill -HUP `cat $nginx_pid`
crontab -e
添加
0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh //每天零点切割日志
vim /usr/local/nginx/conf/vhost/test.com.conf
添加配置如下
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 7d; //有效期
access_log off;
}
location ~ .*\.(js|css)$
{
expires 12h; //有效期
access_log off;
}
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
echo "good good study" > /data/wwwroot/test.com/1.jpg
echo "day day up" > /data/wwwroot/test.com/666.css
curl -x127.0.0.1:80 test.com/1.jpg
curl -x127.0.0.1:80 test.com/666.css
curl -x127.0.0.1:80 test.com/index.html
cat /tmp/1.log
//jpg文件和css文件的访问没有记录log
48.Nginx访问日志、Nginx日志切割、静态文件不记录日志和过期时间
原文地址:http://blog.51cto.com/13569831/2107916