1、Nginx訪問日志
配制訪問日志:
默認定義格式:
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"'; (這是定義日志引用時的名字:combined_realip,后面的內容,就是需要被引用的)
可以理解為:
combined_realip = '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
編輯你需要配制的vhost的conf文件:
vim /usr/local/nginx/conf/vhost/test.com.conf
加入:access_log /tmp/test.com.log combined_realip;(這里的access_log 和/tmp 之間有空格)
檢查語法、重新加載、訪問查看:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
curl -x 127.0.0.1:80 test.com/index.html -I
cat /tmp/test.com.log
2、 Nginx日志切割
在/usr/local/sbin 目錄下創建一個****.sh 文件
定義一個日志腳本:

寫完之后保存退出
語法檢查:
sh -x sh -x /usr/local/sbin/nginx_logs.sh
這樣子nginx的訪問日志給切割出來了。
再定義一個任務計划:
crontab -e
輸入:0 0 * * * /bin/bash /usr/local/sbin/nginx_logs.sh 然后保存退出
這樣子,就可以每天都執行了。
3、靜態文件不記錄日志和過期時間
編輯: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
訪問查看:
到此,靜態文件訪問日志不記錄,和用戶瀏覽器的過期時間配制完成。