reverse proxy nginx docker django

  django, docker, nginx

so what I’m trying to do is to have two web apps: appli1 and appli2. They are served at web.appli1.com and web2.appli2.com but it doesn’t work, even with the port 8001 it sends me to the appli1. so how can I have these two web apps working correctly ?

here is my docker-compose file :

version: '3'

services:
  reverse-proxy:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 8000:8000
      - 8001:8001
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    depends_on:
      - redis
    environment:
      - REDIS_HOST=redis
    #ports: 
      #- "8000:8000"
  web2:
    build: .
    command: python manage.py runserver 0.0.0.0:8001
    depends_on:
      - redis
    environment:
      - REDIS_HOST=redis
  redis:
    image: redis:3.2-alpine
    volumes:
      - redis_data:/data
volumes:  
  redis_data:
 

and here is my nginx.conf file :

events {

}

http {
  server {
    listen 8000;
    server_name web.appli1.com;

    location / {
      proxy_pass http://web:8000;
    }
  }
  server {
    listen 8001;
    server_name web2.appli2.com;

    location / {
      proxy_pass http://web2:8001;
    }
  }
}

I’ve also set the domains in /etc/hosts using ip of host machine

Source: Docker Questions

LEAVE A COMMENT