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

267
Vistas
Nginx reverse proxy map to multiple frontend & backend

I have a angular frontend and a node.js backend, which I want to deploy for clients in different countries. We need for every country one frontend & backend container. So the idea is that nginx should redirect to the correct container inside the docker compose environment based on the path:

example.com/us/frontend -> us frontend container

example.com/us/backend -> us backend container

example.com/fr/frontend -> fr frontend container

example.com/fr/backend -> fr backend container ...

I've implemented so far:

docker-compose.yml

version: "3"
services:
  test-proxy:
    container_name: test-proxy
    image: nginx:latest
    depends_on:
      - example-frontend-us # References the service name.
    volumes:
      - ./config/nginx.conf:/etc/nginx/nginx.conf
      - ./content:/usr/share/nginx/html
    ports:
      - 80:80 # Publishs only port 80 outside of docker compose context.

  example-frontend-us:
    container_name: example-frontend-us
    image: angular-frontend
    ports:
      - 8081:80

nginx.conf:

 http {
    server {

        listen 80;
        server_name localhost 127.0.0.1;

        location = / {
            root /usr/share/nginx/html;
            try_files $uri /index.html;
        }
        

        location /us/frontend {
            proxy_pass          http:/example-frontend-us:8081;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }
    }
}

If I open the browser on localhost/us/frontend I get a 502 Bad Gateway response

If I open the browser on localhost:8081 the frontend is working.

What is wrong here? How can I achieve that nginx is routing to the correct containers?

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

0

Inside the virtual network created by docker compose, you use the internal port numbers. So

proxy_pass          http:/example-frontend-us:8081;

should be

proxy_pass          http://example-frontend-us:80;

(you're also missing a forward slash in http://)

Finally, you don't need to map the port on example-frontend-us unless you want to be able to reach it directly and bypass nginx.

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