Score:1

Nginx: proxy_pass ignores port

ar flag

I have an application with Swagger on localhost:8080/swagger/.

I need a redirect from localhost:80 to actual swagger url which is localhost:8080/swagger/ so I setup a Nginx reverse proxy:

server {
    listen 80;

    server_name=_;
    
    location / {
           proxy_pass http://localhost:8080/swagger/;
           proxy_redirect off;
           proxy_set_header Host $http_host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

So when I enter localhost:80 I recieve 301 code and redirect to localhost:80/swagger/index.html. But I need port 8080 , why nginx ignores port in proxy_pass?

Score:-1
kr flag

you can modify the listen directive for the server block listening on port 80 to also include the port number:

listen 80 default_server;

This will make Nginx listen on port 80 and route traffic to http://localhost:8080/swagger/ while retaining the port number in the URL.

xmm_581 avatar
ar flag
Still does not helps. When I curl localhost/ or trying access page on browser it routes me to `localhost/swagger/index.html` with 301 code and blank page ,not the localhost:8080/swagger/index.html. It retains port, but i just need to retrieve not blank page which is on 8080 port. I changed also path from '/' to '/docs/' and now recieving 404 error which is logical, because it routes me to 80/swagger/ completely ignoring the port I set in proxy_pass.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.