Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

316
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda