Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I read and manipulate POST request variables with nginx?
    primarykey
    data
    text
    <p>I'm using nginx (v1.4.1) to proxy an external service, but would like to be able to inspect and possibly modify the body of a <code>POST</code> request before proxying it. The problem is, I'm currently unable to access the <code>POST</code> request body while handling the request, whether through the <code>$request_body</code> variable or otherwise.</p> <p>I've read a number of posts and SO questions, and have implemented <a href="https://stackoverflow.com/questions/4939382/logging-post-data-from-request-body">this suggested strategy</a>, which is intended to allow the logging of the <code>POST</code> body (when using a <code>proxy_pass</code> directive). However, while this works for me I'm still unable to read anything from <code>$request_body</code> during the processing of the request.</p> <p>For clarity, here's the relevant section of my configuration:</p> <pre><code>location /proxy-this/ { client_max_body_size 8k; client_body_buffer_size 16k; client_body_in_single_buffer on; proxy_pass https://example.com/external-endpoint/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header Content-Length ''; } </code></pre> <p>And what I'd like to be able to do:</p> <pre><code>location /proxy-this/ { ... (same configuration as above) ... set $request_body $request_body&amp;extra_param=1; } </code></pre> <p>I'm aware that this is possible using the <code>nginx_lua</code> module, and have looked at the <code>HttpFormInputModule</code>, but the first seems overkill and the latter hasn't been updated in a while.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload