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

Nginx訪問日誌

日誌格式咱們能夠在主配置文件看到css

#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_agentnginx

除了在主配置文件nginx.conf裏定義日誌格式外,還須要在虛擬主機配置文件中增長
access_log /tmp/1.log combined_realip;
#vim /usr/local/nginx/conf/vhost/test.com.conf

Nginx訪問日誌、靜態文件不記錄過時時間
這裏的combined_realip就是在nginx.conf中定義的日誌格式名字 vim

# /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           //從新加載
相關文章
相關標籤/搜索