1

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?

1 Answer 1

-1

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.

1
  • 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.
    – xmm_581
    Commented Mar 6, 2023 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .