天天看點

nginx 用log_format設定日志格式

  1. #vim /usr/local/nginx/conf/nginx.conf
  2. log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘‘$status $body_bytes_sent “$http_referer” ‘‘”$http_user_agent” $http_x_forwarded_for’;
  3. include /usr/local/nginx/conf/vhost/*.conf;
  1. #vim /usr/local/nginx/conf/vhost/web.conf
  2. server
  3. {
  4. listen 80 default;
  5. server_name www.msits.com;
  6. index index.html index.htm index.php;
  7. root /data/httpd/msits.com;
  8. location ~ .*\.php?$
  9. include fastcgi.conf;
  10. fastcgi_pass 127.0.0.1:9000;
  11. fastcgi_index index.php;
  12. }
  13. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  14. expires 30d;
  15. location ~ .*\.(js|css)?$
  16. expires 1h;
  17. access_log /usr/local/nginx/logs/access.log access;
  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 :記錄用戶端浏覽器的相關資訊;

繼續閱讀