jeudi 23 novembre 2017

Nginx & Docker: nginx fails to route to correct containers

I recently tried to set up nginx to route incoming traffic to different docker containers. Aside from site1, the other three sites seam to all route to one container, and sometimes that container changes on a restart.

After launching all of the docker containers, there doesn't seam to be any docker logs for nginx.

As far as I can tell all of the subsequent containers are running correctly (they are running Node.js)

my docker-compose.yml:

    version: '2'

services:
  resume:
    build:
      context: ../WebServer/
      dockerfile: Dockerfile
    volumes:
      - ../WebServer/app/publicFiles:/app/publicFiles
  globalmedical:
    build:
      context: ../globalMedical/
      dockerfile: Dockerfile
    volumes:
      - ../globalMedical/app/publicFiles:/app/publicFiles
  webjcl:
    environment:
      - NODE_DEBUG=fs
    build:
      context: ../webjcl/
      dockerfile: Dockerfile
    volumes:
      - ../webjcl:/app
  mongo:
    image: 'mongo:3'
    depends_on:
      - webjcl
  hack:
    build:
      context: ../Hack/
      dockerfile: Dockerfile
    volumes:
      - ../Hack/app/publicFiles:/app/publicFiles
  reverseproxy:
    links:
      - resume:resume
      - globalmedical:globalmedical
      - webjcl:webjcl
      - hack:hack
    build:
      context: ./
      dockerfile: Dockerfile
    ports:
      - 80:80
    restart: always

nginx.conf:

worker_processes 1;

events { worker_connections 1024; }

http {
    sendfile on;
    upstream globalmedical {server globalmedical:80 weight=10 max_fails=3 fail_timeout=30s;}
    upstream resume {server resume:80 weight=10 max_fails=3 fail_timeout=30s;}
    upstream webjcl {server webjcl:80 weight=10 max_fails=3 fail_timeout=30s;}
    upstream hack {server hack:80 weight=10 max_fails=3 fail_timeout=30s;}
    server {
        listen 80;
        server_name site1.net;
        location / {
            proxy_pass         http://resume;
            proxy_redirect     off;
            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-Host $server_name;
        }
    }

    server {
        listen 80;
        server_name site2.com;
        location / {
            proxy_pass         http://hack;
            proxy_redirect     off;
            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-Host $server_name;
        }
    }

    server {
        listen 80;
        server_name site3.net;
        location / {
            proxy_pass         http://globalmedical;
            proxy_redirect     off;
            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-Host $server_name;
        }
    }

    server {
        listen *:80;
        server_name site4.com;
        location / {
            proxy_pass         http://webjcl;
            proxy_connect_timeout       600;
            proxy_send_timeout          600;
            proxy_read_timeout          600;
            send_timeout                600;
            proxy_redirect     off;
            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-Host $server_name;
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire