在nginx日志的access log中记录post请求的参数值
来源:互联网 发布:广州学网络推广 编辑:程序博客网 时间:2024/05/28 11:29
背景:有时程序偶出现参数少了或没有提交到下一个链接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.conflog_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学习网
- 在nginx日志的access log中记录post请求的参数值
- [nginx]如何在access log中记录post请求的参数
- nginx日志记录post的参数
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- 通过Nginx,Tomcat访问日志(access log)记录请求耗时
- tomcat访问(access)日志配置、记录Post请求参数
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- Tomcat的访问日志-localhost_access_log和记录Post请求参数
- hive 分析nginx的access.log日志
- retrofit的 get post 请求 + log日志
- nginx把post的数据记录到日志中
- nginx log 记录请求的头信息
- Nginx正确记录post日志的方法
- 让nginx日志支持记录POST请求
- nginx记录响应与POST请求日志
- nginx 出现不该出现的 access.log 日志
- nginx access.log 忽略favicon.ico访问记录的方法
- Okhttp的Post请求参数在Interceptor中修改
- 色拉寺旅游看点
- UVA Uniform Generator
- IOS开发——在程序中获取Info.plist中的字段
- Ruby:The provided regular expression is using multiline anchors (^ or $), which may present a securi
- 如何获取jQuery集合的某一项
- 在nginx日志的access log中记录post请求的参数值
- iOS 获得当前系统语言
- MyEclipse 启动报错:'Building workspace' has encountered a problem解决方法
- 分享一个在工作中遇到的一个问题的解决方案
- 业务系统需要怎样的全局唯一ID? #Ticktick#(环信首席架构师:一乐)
- IOS模型分层网络协议
- HDU - 1856 - More is better <并查集>
- hadoop mr reduce类变量使用问题整理
- Eclipse 安装最新SVN插件