nginx $request_method gets changed from POST to GET before logging due to internal redirects

by Akki   Last Updated November 14, 2017 18:00 PM

NGINX Version: 1.10.3 on a Debain 9.1 OS with Jessie-Backports
nginx.conf:

user www-data;
pid /var/run/nginx.pid;
worker_processes  1;
error_log /var/log/nginx/error.log;
events {
    worker_connections 1024;
}
http {
    log_format main 'request_method:$request_method request:$request';
    server {
        listen 80;
        error_page  405  =200 $uri;
        access_log /var/log/nginx/access.log main;
        location / {
            default_type text/html;
            root   /usr/share/nginx/html/;
            include mime.types;
            index  index.html index.htm index.asp index.aspx index.php default.html default.htm default.asp default.aspx default.php;
        }
        error_page   403                       /403.html;
        error_page   400 401 402 404           /404.html;
        error_page   500 502 503 504           /50x.html;
        location = /400.html {
                root    /usr/share/nginx/error-pages/Apache/2.4.20;
        }
        location = /403.html {
                root    /usr/share/nginx/error-pages/Apache/2.4.20;
        }
        location = /404.html {
                root    /usr/share/nginx/error-pages/Apache/2.4.20;
            }
        location = /50x.html {
                root    /usr/share/nginx/error-pages/Apache/2.4.20;
        }
    }
}

When I POST this server since nginx cannot serve static pages on POST, I get a 405 response code. But I need to serve static page on a POST request also. So most workarounds on the internet suggested this snippet of code = error_page 405 =200 $uri;
This worked fine for the purpose of serving static content to a POST request with response code 200, BUT
Due to the $uri, internal redirects of nginx causes the $request_method to change from POST to GET and in the /var/log/nginx/access.log, I get this:

request_method:GET request:POST /Login.html HTTP/1.1\n
instead of
request_method:POST request:POST /Login.html HTTP/1.1\n

Any workaround to solve this?

Tags : nginx http


Related Questions



Expire 410 responses in nginx

Updated May 17, 2017 17:00 PM

Nginx: How to set expiration for 404 responses?

Updated September 28, 2017 01:00 AM


Varnish: Invalidate URL cache with http header

Updated July 03, 2017 20:00 PM