1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Nginx Reverse Proxy Issue with Multiple Angular Applications in Docker

Discussão em 'Angular' iniciado por JEKES, Abril 2, 2025.

  1. JEKES

    JEKES Guest

    I have some trouble running multiple Nginx containers in a Docker environment to serve different versions of an Angular application. The setup includes:

    • mobile-v1: An older AngularJS application served on port 8090.
    • mobile-v2: A new Angular version served on port 8091.
    • A reverse proxy Nginx container to manage domain-based routing on port 80.

    While I can successfully ping the containers and make direct curl requests (curl -I http://mobile-v2:8091), accessing the applications through the reverse proxy (curl -I http://localhost) returns a 403 Forbidden error.

    Docker-Compose Configuration:
    services:
    mobile-v1:
    build:
    context: ../staging/cplan-v1-mobile-frontend
    dockerfile: ../../cplan-docker-compose/dockerfiles/staging/mobile-v1.Dockerfile
    container_name: mobile-v1
    ports:
    - "8090:8090"
    volumes:
    - ./nginx/staging/front-services/cplan-mobile-v1.conf:/etc/nginx/conf.d/default.conf
    - ./logs/staging/nginx:/var/log/nginx
    - /etc/timezone:/etc/timezone:ro
    - /etc/localtime:/etc/localtime:ro
    networks:
    - app-network
    restart: always

    mobile-v2:
    build:
    context: ../staging/cplan-v2-mobile-frontend
    dockerfile: ../../cplan-docker-compose/dockerfiles/staging/mobile-v2.Dockerfile
    container_name: mobile-v2
    ports:
    - "8091:8091"
    volumes:
    - ./nginx/staging/front-services/cplan-mobile-v2.conf:/etc/nginx/conf.d/default.conf
    - ./logs/staging/nginx:/var/log/nginx
    - /etc/timezone:/etc/timezone:ro
    - /etc/localtime:/etc/localtime:ro
    networks:
    - app-network
    restart: always

    networks:
    app-network:
    driver: bridge


    Reverse Proxy Nginx Configuration:

    server {
    listen 80;
    listen [::]:80;
    server_name mobile-v1.xxx.fr;

    location / {
    proxy_pass http://mobile-v1:8090;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }

    server {
    listen 80;
    listen [::]:80;
    server_name mobile-v2.xxx.fr;

    location / {
    proxy_pass http://mobile-v2:8091;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }


    Nginx Configuration for mobile-v2:

    server {
    listen 8091;
    listen [::]:8091;

    server_name mobile-v2;

    root /usr/share/nginx/html/mobile-v2;
    index index.html;

    access_log /var/log/nginx/access-mobile-v2.log;
    error_log /var/log/nginx/error-mobile-v2.log;

    location / {
    try_files $uri /index.html;
    }
    error_page 404 /index.html;
    }


    Tests Conducted (From host container nginx proxy)

    • ping mobile-v2 → Success
    • curl -I http://mobile-v2:8091 → Success (Returns HTTP 200 OK)
    • curl -I http://localhost → Fails with HTTP 403 Forbidden

    I've built the mobile app using Docker's multi-stage build feature. Previously, I explored sharing a volume between the Nginx proxy and the Angular app. It worked, but it wasn’t very convenient for recompiling the app.

    If anybody have an idea it will be helpful

    Continue reading...

Compartilhe esta Página