NGINX: Reverse proxy gives 405 Not Allowed when doing POST
Issue
Flask app with UI failed to access when setup with nginx show error: 405 Not Allowed. Here is the config:
location /rmbg {
proxy_pass http://127.0.0.1:5100/;
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_set_header Host $host;
proxy_redirect off;
}
Cause
Html form action
for post is still located at original location /
<form
id="uploadForm"
action="/"
method="post"
enctype="multipart/form-data"
>
<input id="fileInput" type="file" name="file" />
<input type="submit" value="rm" />
</form>
Resolution
Change location match with nginx:
<form
id="uploadForm"
action="/rmbg"
method="post"
enctype="multipart/form-data"
>
<input id="fileInput" type="file" name="file" />
<input type="submit" value="rm" />
</form>