Nginx 用log_format設置日志格式


1、配置文件
#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;
 
2、vhost中配置文件
 #vim /usr/local/nginx/conf/vhost/web.conf
 server
 {
 listen 80 default;
 server_name www.linuxidc.com;
 index index.html index.htm index.php;
 root /data/httpd/linuxidc.com;
 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/access.log access;
 }
 
3、相關說明解釋
 1.$remote_addr 與$http_x_forwarded_for 用以記錄客戶端的ip地址;
 2.$remote_user :用來記錄客戶端用戶名稱;
 3.$time_local : 用來記錄訪問時間與時區;
 4.$request : 用來記錄請求的url與http協議;
 5.$status : 用來記錄請求狀態;成功是200,
 6.$body_bytes_s ent :記錄發送給客戶端文件主體內容大小;
 7.$http_referer :用來記錄從那個頁面鏈接訪問過來的;
 8.$http_user_agent :記錄客戶端瀏覽器的相關信息;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM