I'm using nginx as a reverse proxy server.
My application servers behind it accept custom extension methods for requests. For example, "MYMETHOD".
However the nginx default configuration seems to only accept non-extension methods, such as HEAD, GET, POST, etc, and returns a default nginx 400 response for requests that did not have a non-extension method, instead of proxying those requests to my app servers.
How can I make nginx accept and proxy any http requests regardless of their method?
I do not want to whitelist specific methods, because this would require me to change the nginx configuration every time I need to support a new method in my app servers, and I do not want those to be tightly coupled.
[edit]
The solution has to work for official supported nginx distributions, either on nginx.com or popular linux distributions (debian, centos, etc).
Obviously I can just alter the nginx source code and make it pass along any methods, but if I'm altering the source code and recompiling it's no longer nginx but rather a fork of it.
You can use ngx_http_allow_methods_module for allowing custom HTTP methods. This module allows arbitrary HTTP methods to be passed to a backend application.
Example:
http {
    server {
        location /api/ {
            allow_methods ".*";
        }
    }
}
Directive
allow_methods "^(GET|POST|PUT|DELETE|PATCH|LINK|COPY)$";
This directive describes HTTP methods that should be passed along. The pattern is case-sensitive (as per RFC 2616). If it is absent, the default rules of Nginx apply. You should use this directive only in the locations that you really need it in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With