Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
How to listen to one port and reverse proxy to several ports in Nginx?

I have been able to make a reverse proxy using Nginx to redirect POST requests made to the 8080 port to the 8081 port. Now, I would like to redirect them to the 8082 additionally.

events {}

http {
        server {
                listen 127.0.0.1:8080;
                location / {
                        proxy_pass http://127.0.0.1:8081/;
                }
                location /api/ {
                        proxy_pass http://127.0.0.1:8082/;
                }
        }
}

But by doing this, I'm only receiving the requests on the 8081 port, and not on the 8082 with the /api endpoint. Also, I would like to not use any endpoint ( / ) on both reverse proxy configuration if possible.

Thanks.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think the problem is that the server listening on port 8082 actually is receiving the traffic, but you're getting an error because the proxy is requesting /api/ rather than /, since it's literally just forwarding the request. If this actually is the problem, rewriting the request before passing it off via the proxy should do the trick.

server {
    listen 127.0.0.1:8080;
        location / {
            proxy_pass http://127.0.0.1:8081/;
        }
        location /api/ {
            rewrite /api/(.*) /$1 break;
            proxy_pass http://127.0.0.1:8082/;
        }
    }
}

Unfortunately, I'm not really sure what you mean by your last sentence. Do you mean that you want the api endpoint to be reachable via the base URI as well?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda