Nginx日誌中request_body為空白

來源:互聯網
上載者:User

標籤: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為空白

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.