stop nginx from changing port after post request from html

Viewed 20

I have a number of dockerized web apps on the same machine. All the apps are flask + waitress, have a single endpoint each and differ only by port (localhost:50xx/ui).
Also all the apps have a form inside html, that create a POST request to the same /ui endpoint.

<form action="/ui" enctype="multipart/form-data" method="POST">
    <input accept=".jpg,.png,.jpeg" name="file" type="file"/>
    <input type="submit"/>
</form>

I was trying to configure an nginx server to serve as a reverse proxy. The idea is to have all the apps on different endpoints of the same server name. The problem is that that POST request from html overrides the server name and the port. I've managed to solve the problem with server name, but not the port.

Say, I have a service on localhost:5001/ui
I want it to be on somename/the-service
I can achieve it with a config in the end (might have broken something during renaming everything to ask a question), but once I submit form in the service, I'm redirected to somename/ui, but I want to stay on somename/the-service

server {
    error_log stderr warn;
    listen       80;
    server_name  somename;

    location / {
    
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        
    }
    

    
    location ~ "\.(htm|html|js|css|svg|png)$" {
        return 307 http://localhost:5004$request_uri;
    }
    
    
    
    location /the-service {
        proxy_pass http://localhost:5004/ui;
    }
    
    location /ui {
        proxy_pass http://localhost:5004/ui;
        proxy_set_header Host $host;
        
    }
    
    
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    
}

I really hope my explanation is somewhat clear

0 Answers
Related