Nginx訪問日誌
日誌格式我們可以在主配置文件看到
#vim /usr/local/nginx/conf/nginx.conf //搜索log_format
$remote_addr 客戶端ip(公網ip)
$http_x_forwarded_for 代理服務器ip
$time_local 服務器本地時間
$host 訪問主機名(域名)
$request_uri 訪問的uri地址
$status 狀態碼
$http_referer referer
$http_user_agent user_agent
除了在主配置文件nginx.conf裏定義日誌格式外,還需要在虛擬主機配置文件中增加
access_log /tmp/1.log combined_realip;
#vim /usr/local/nginx/conf/vhost/test.com.conf
這裏的combined_realip就是在nginx.conf中定義的日誌格式名字
# /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/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 //重新加載