部署Nginx,查看Nginx日志的时候,发现request_body的值没有记录下来
Nginx日志:
10.10.10.10--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0020.701
10.10.10.10--2016-02-24T13:33:54+08:00POST /rate_plan HTTP/1.12002----0.0010.617
10.10.10.10--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; }