想做某些测试需要打印post请求的参数,故想到用nginx的echo直接
echo $request_body就完了呗,配置如下:

    location /testecho {
        default_type        'text/plain'; 
        echo                '$args $request $request_body';
    }

post参数过去后发现$request_body是空的,什么也没打出来,google下发现了作者的解释,

Sorry, forgot to mention that for POST data that has well exceeded
"client_body_buffer_size", Nginx will write the data into temporary
files on the disk. In this case, the $request_body variable is also
evaluated to an empty string ("").
To help demonstrating this, I've added the "read_request_body"
directive to my "echo" module (released as v0.14), which calls the
"ngx_http_read_client_request_body" function, just as the "proxy"
module and many others. The following example clearly shows the
situation described above.
In the nginx.conf:
  location /echobody {
    client_body_buffer_size 2;
    echo_read_request_body;
    echo $request_body;
  }

大意是说post的数据超越了client_body_buffer_size所定义的大小,那么nginx会将这些数据写入磁盘上的临时文件,在这种情况下,这个request_body就会被设为"",为了解决这个问题,作者开发一个模块可以读取post的数据,并使用read_request_body这个指令进行指定执行。所以加上去自然就好了。以此备忘。

标签: none

添加新评论