Nginx訪問日誌、靜態文件不記錄過期時間

                                                  Nginx訪問日誌

日誌格式我們可以在主配置文件看到

#vim /usr/local/nginx/conf/nginx.conf                     //搜索log_format

Nginx訪問日誌、靜態文件不記錄過期時間

$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

Nginx訪問日誌、靜態文件不記錄過期時間
這裏的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                           //查看日誌的格式

Nginx訪問日誌、靜態文件不記錄過期時間

                                           靜態文件不記錄過期時間
#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           //重新加載
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章