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

283
Visualizações
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 Respostas
Responde à pergunta

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 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