Nginx访问日志

12.10 Nginx访问日志

除了在主配置文件nginx.conf里定义日志格式外,还需要在虚拟主机配置文件中增加

access_log /tmp/1.log combined_realip;

这里的combined_realip就是在nginx.conf中定义的日志格式名字

12.11Nginx日志切割

#! /bin/bash
d=`date -d "-1 day" +%Y%m%d` 
logdir="/data/logs"
nginx_pid="/usr/local/nginx/logs/nginx.pid"
cd $logdir
for log in `ls *.log`
do
    mv $log $log-$d
done
/bin/kill -HUP 'cat $nginx_pid'
计划任务:

 0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh

12.12 静态文件不记录日志和过期时间

修改配置文件

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
          expires      7d;
          access_log off;
    }
location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }

猜你喜欢

转载自my.oschina.net/u/3803395/blog/1815583