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

后端 未结 6 1155
孤独总比滥情好
孤独总比滥情好 2020-11-29 20:23

I have a problem in trying to do a POST request in my application and I searched a lot, but I did not find the solution.

So, I have a nodeJS application and a websi

6条回答
  •  野性不改
    2020-11-29 21:08

    I have tried the solution which redirects 405 to 200, and in production environment(in my case, it's Google Load Balancing with Nginx Docker container), this hack causes some 502 errors(Google Load Balancing error code: backend_early_response_with_non_error_status).

    In the end, I have made this work properly by replacing Nginx with OpenResty which is completely compatible with Nginx and have more plugins.

    With ngx_coolkit, Now Nginx(OpenResty) could serve static files with POST request properly, here is the config file in my case:

    server {
      listen 80;
    
      location / {
        override_method GET;
        proxy_pass http://127.0.0.1:8080;
      }
    }
    
    server {
      listen 8080;
      location / {
        root /var/www/web-static;
        index index.html;
        add_header Cache-Control no-cache;
      }
    }
    

    In the above config, I use override_method offered by ngx_coolkit to override the HTTP Method to GET.

提交回复
热议问题