POST request not allowed - 405 Not Allowed - nginx, even with headers included POST request not allowed - 405 Not Allowed - nginx, even with headers included express express

POST request not allowed - 405 Not Allowed - nginx, even with headers included


This configuration to your nginx.conf should help you.

https://gist.github.com/baskaran-md/e46cc25ccfac83f153bb

server {    listen       80;    server_name  localhost;    location / {        root   html;        index  index.html index.htm;    }    error_page  404     /404.html;    error_page  403     /403.html;    # To allow POST on static pages    error_page  405     =200 $uri;    # ...}


This is the real proxy redirection to the intended server.

server {  listen          80;  server_name     localhost;location / {        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header X-NginX-Proxy true;    proxy_pass http://xx.xxx.xxx.xxx/;    proxy_redirect off;    proxy_set_header Host $host;  }}


I noticed this wasn't working with a static-first-then-reverse-proxy setup. Here's what that looks like:

location @app {  proxy_pass http://localhost:3000$request_uri;}location / {  try_files $uri $uri/ @app;  error_page 405 @app;}