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

146
Vistas
NGINX reverse proxy for multiple locations not working

I am trying to run two express.js APIs in an EC2 instance with the help of PM2 and reverse-proxy using NGINX. Please find the NGINX config below,

NGINX config for the locations

My intention is to run the 2 APIs under the following routes:

  1. / to reverse proxy localhost:3000
  2. /local to reverse proxy localhost:3001

To make things more clear, I need the URL containing /local or /local/ to proxy the API running on the port 3001. However, when I try to hit https://example.com/local or https://example.com/local/, the response is received from the API running in port 3000 instead of the intended proxy.

This is the response returned when tried in the browser:

Safari screenshot

The solution needed is to successfully configure the 2 APIs to consume requests from the / aka root domain and the /local domain respectively. But both the requests go to the first one.

PS. I was also advised with a trick - tried switching the location positions (i.e. keeping the /local location block first followed by the / block) in the config file, still no luck - same behaviour.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The reverse proxy works fine redirecting the requests to the correct server, but the one running on '/local' gets requests forwarded containing '/local'. So the express app present there looks for /local in the route, but i figured out that was not configured. So have something like this.

app.get('/local', (req, res) => {
  res.send('Hello World2!')
})

Just make sure to add the prefix '/local' for all the routes in the express app server at '/local' from nginx

And

"PS. I was also advised with a trick - tried switching the location positions (i.e. keeping the /local location block first followed by the / block) in the config file, still no luck - same behaviour."

The above will be the correct config because nginx will match and redirect the requests to the first applicable block. So if '/' stays before '/local' all the requests will be redirected to the first express app.

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