背景:有時程序偶出現參數少了或沒有提交到下一個鏈接Url里后出現問題,如何查呢,最好的辦法是在nginx上的加post參數,以定位到問題才有可能對某個UIR的代碼出現的問題進行排查。
og_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for';
access_log logs/test.access.log access;
注意放的位置在http里:nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/vhost/xxx.conf:59
nginx.conf
http里定義:wwwlog
log_format wwwlog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for "$request_time"';
在include每個域名里后面加上wwwlog:
access_log /data/logs/access_mytv.log wwwlog;
於是在同樣的access后這樣寫:
nginx.conf log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for'; 包含的justwinit.conf: access_log /data/logs/access_mytv.log access
日志如下:
202.108.16.77 - - [14/Jan/2015:10:45:45 +0800] "POST /partin/releaseinfo HTTP/1.1" 302 5 id=47&choice_type=new&eid=338&videoid=5d6dabda-9b97-11e4-9584-21fa84a4ab6e&file_ext=mp4&lang=zh&upload_server=202.108.17.15&title=7%E5%B2%81%E5%B0%8F%E5%AD%A9%E9%85%92%E7%93%B6%E4%B8%8A%E5%81%9A%E4%BF%AF%E5%8D%A7%E6%92%91%E8%B9%BF%E7%BA%A2%E7%BD%91%E7%BB%9C&desc=7%E5%B2%81%E5%B0%8F%E5%AD%A9%E9%85%92%E7%93%B6%E4%B8%8A%E5%81%9A%E4%BF%AF%E5%8D%A7%E6%92%91%E8%B9%BF%E7%BA%A2%E7%BD%91%E7%BB%9C&tags=%E6%B5%8B%E8%AF%95%E4%B8%80%E4%B8%8B%E3%80%82&checkflag=on "http://justwinit.cn/partin/showupload/activityid/47" "Mozilla/5.0 (Windows NT 6.1; rv:34.0) Gecko/20100101 Firefox/34.0" -
POST URI及參數:POST /partin/releaseinfo HTTP/1.1" 302 5 .....
來自的refer Uri:http://justwinit.cn/partin/showupload/activityid/47
這個access_log的log_format應該可以定義多個不同的名供不同日志的需求。
再就是,
get請求的參數就是存放在http header中的,所以修改header的大小限制 當然可以解決請求串過長的問題啦。
移動互聯網行業開發過程中,服務端經常會需要檢查是否收到請求,收到什么樣的請求,最簡單的辦法就是看nginx的access log,常見的nginx配置中access log一般都只有GET請求的參數,而POST請求的參數卻不行。
http://wiki.nginx.org/NginxHttpCoreModule#.24request_body
$request_body
This variable(0.7.58+) contains the body of the request. The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass.
正如上文件所示,只需要使用$request_body即可打出post的數據,在現存的server段加上下面的設置即可:
log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for';
access_log logs/test.access.log access;
- 本文來自:Linux學習網