日誌格式css
vim /usr/local/nginx/conf/nginx.conf //搜索log_format
combined_realip //規則名字html
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
添加nginx
0 0 * * * /bin/bash /usr/local/sbin/nginx_log_rotate.sh //天天零點切割日誌
vim /usr/local/nginx/conf/vhost/test.com.conf
添加配置以下shell
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文件的訪問沒有記錄logvim