【问题】Nginx日志中request_body为空
2016-02-24 15:26
676 查看
部署Nginx,查看Nginx日志的时候,发现request_body的值没有记录下来
Nginx日志:
192.168.1.1--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0020.701
192.168.1.1--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0010.617
192.168.1.1--2016-02-24T13:37:44+08:00POST /rate_plan HTTP/1.12002----0.0020.502
问题可能原因:
当 nginx 尚未读取请求体的时候,或者请求体有一部分或者全部缓冲到临时文件的时候,$request_body 和 $echo_request_body 都将是空值。
Nginx 读取请求体是按需的,如果使用 ngx_proxy 模块的话,读取发生在 content 请求处理阶段。所以如果在早于 content 阶段之前的阶段(比如 rewrite 阶段)去读取 $request_body,则必是空值
处理办法在nginx.conf配置文件中添加了两个配置项:
fastcgi_buffers 32 8k;#指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答。
client_body_buffer_size 1024k; #缓冲区代理缓冲用户端请求的最大字节数
Nginx日志:
192.168.1.1--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0020.701
192.168.1.1--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0010.617
192.168.1.1--2016-02-24T13:37:44+08:00POST /rate_plan HTTP/1.12002----0.0020.502
问题可能原因:
当 nginx 尚未读取请求体的时候,或者请求体有一部分或者全部缓冲到临时文件的时候,$request_body 和 $echo_request_body 都将是空值。
Nginx 读取请求体是按需的,如果使用 ngx_proxy 模块的话,读取发生在 content 请求处理阶段。所以如果在早于 content 阶段之前的阶段(比如 rewrite 阶段)去读取 $request_body,则必是空值
处理办法在nginx.conf配置文件中添加了两个配置项:
fastcgi_buffers 32 8k;#指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答。
client_body_buffer_size 1024k; #缓冲区代理缓冲用户端请求的最大字节数
worker_processes 2; daemon off; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr$remote_user$http_user_name$time_iso8601$request' '$status$body_bytes_sent$request_body$http_referer$http_user_agent' '$http_x_forwarded_for$upstream_response_time$request_time'; sendfile on; keepalive_timeout 65; client_max_body_size 100m; fastcgi_buffers 32 8k; client_body_buffer_size 1024k; server { listen 80; server_name localhost; charset utf-8; location = / { root html; index index.html index.htm; error_page 405 =200 $uri; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } error_page 405 =200 /index.html; } include conf.d/*.conf; }
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- web 应用中常用的各种 cache详解
- Linux系统上配置Nginx+Ruby on Rails+MySQL超攻略
- php错误提示failed to open stream: HTTP request failed!的完美解决方法
- window+nginx+php环境配置 附配置搭配说明
- 小论asp中request与response的用法
- 循环取值Request.QueryString的用法
- Jquery中request和request.form和request.querystring的区别