nginx 日誌格式

一、配置文件
   #vim /usr/local/nginx/conf/nginx.conf
   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" $http_x_forwarded_for';

   include /usr/local/nginx/conf/vhost/*.conf;
二、vhost中配置
   #vim /usr/local/nginx/conf/vhost/www.abc.com.conf
   server
{
        listen       80 default;
        server_name  www.bac.com;
        index index.html index.htm index.php;
        root  /data/httpd/csm.shopex.cn;      
        
        location ~ .*\.php?$
        {
            include fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
                expires      1h;
        }

        access_log /usr/local/nginx/logs/csm.log access; 

}
三、說明
$remote_addr   與$http_x_forwarded_for 用以記錄客戶端的ip地址;
$remote_user   :用來記錄客戶端用戶名稱;
$time_local  : 用來記錄訪問時間與時區;  
$request  :  用來記錄請求的url與http協議;
$status     :  用來記錄請求狀態;成功是200,
$body_bytes_s ent  :記錄發送給客戶端文件主體內容大小;
$http_referer  :用來記錄從那個頁面連接訪問過來的;
$http_user_agent  :記錄客戶毒啊瀏覽器的相關信息;php

相關文章
相關標籤/搜索