標籤:nginx request_body fastcgi_buffers client_body_buffer_size
部署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; #緩衝區代理緩衝使用者端請求的最大位元組數
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;}
本文出自 “巧克力黑” 部落格,請務必保留此出處http://10120275.blog.51cto.com/10110275/1744648
Nginx日誌中request_body為空白