若是你對nginx日誌格式,有這樣那樣的要求。php
那麼就看一下說明吧。html
$remote_addr The remote host $remote_user The authenticated user (if any) $time_local The time of the access $request The first line of the request $status The status of the request $body_bytes_sent The size of the server's response, in bytes $http_referer The referrer URL, taken from the request's headers $http_user_agent The user agent, taken from the request's headers
若是你想記錄某個cookie或者header裏面的值的話linux
$cookie_[COOKIE_NAME]
$http_[HEADER_NAME]
咱們來看下面的測試配置:nginx
http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user $server_name [$time_local] "$request" ' '$status $body_bytes_sent "$request_body" "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "clickpid=$cookie_clickpid" "clickaid=$cookie_clickaid"'; access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8080; server_name localhost; #charset koi8-r; access_log logs/host.access.log main; location ~ \.php$ {
#這裏會記錄post數據 access_log logs/post.log main; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1; } location / {
#這裏不會記錄post數據 root html; index index.html index.htm; }
The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass.web
只有在用了proxy_pass或者fastcgi_pass標記的location{ }裏面變量$request_body纔會生效。cookie
可參考:app
http://www.cnblogs.com/meteorx/p/3188647.htmltcp
另外,還能夠參考:post
http://articles.slicehost.com/2010/8/27/customizing-nginx-web-logs測試
日誌滾動,能夠參考:
http://linux008.blog.51cto.com/2837805/555829/ 使用logrotate
或者手動寫腳本crontab 來執行:
#!/bin/sh mv /usr/local/Cellar/nginx/1.6.2/logs/host.access.log /usr/local/Cellar/nginx/1.6.2/logs/host.access.log.2015.4.3 kill -USR1 `cat /usr/local/var/run/nginx.pid` sleep 1
這裏mv須要本身判斷是否存在重名文件。