$request_method variable shows wrong value

Maxim Dounin mdounin at mdounin.ru
Wed Jan 18 12:32:04 UTC 2017


On Tue, Jan 17, 2017 at 11:48:51AM -0500, mastercan wrote:

> I have a setup where I'm using an Accel-Redirect header in php like this:
> header("X-Accel-Redirect: /testxxx.php?".$_SERVER['QUERY_STRING']);
> Furthermore I'm using HTTP/2.0 and SSL, running on nginx 1.11.8.
> The problem is: When doing a POST request on my upload.php (which then does
> an x-accel-redirect to testxxx.php) the $request_method has the value
> "GET".

That's correct.  After a redirection via X-Accel-Redirect to an 
URI, the request method is changed to GET, much like it happens 
after error_page redirections (see http://nginx.org/r/error_page).  
If you want to preserve the original request method, use 
a redirection to a named location.

> I have a section in my nginx php config where I use "add_header" to output
> the value of $request_method. So that's how I know this value is set to
> "GET".
> Some weeks ago this was working correct. All I changed since then was
> switching to HTTPS.

This might work previously with old nginx versions, as previously 
there was a bug which preserved original request method string 
representation after X-Accel-Redirect.  The bug was fixed in nginx 

    *) Bugfix: proxying used the HTTP method of the original request after
       an "X-Accel-Redirect" redirection.

This also affects the $request_method variable value you use.

Maxim Dounin

More information about the nginx mailing list