nginx proxy_pass, docker-compose, two different containers, same domain

Viewed 100

I am having trouble setting up an nginx reverse proxy to serve content from different containers depending on the URI.

I have three docker images: (1) a flask app that serves a website (2) a bokeh app that serves a dashboard, (3) nginx to direct external requests to either (1) or (2). I build and run the stack using docker-compose. After running the stack (docker-compose -f docker-compose-local.yaml up):

  • I can, as expected, access (1) flask app via (3) nginx at localhost:1337.
  • I can, as expected, access (2) bokeh app directly at localhost:8002
  • I cannot access (2) the bokeh app via (3) nginx at localhost:1337/dboard

I would like the user to experience the dashboard as though it is part of the website, when on the backend the dashboard is in one container and all the other content is in a different container.

I have read a great many stackoverflow questions (e.g. here, here), serverfault questions (e.g. here, here), and blog posts, tried all manner of permutations of trailing slashes in the dashboard nginx location line and its proxy_pass, a number of proxy_set_header directives. I've gotten all sorts of "404 not found" and "502 bad gateway" responses, but so far no luck accessing the dashboard through nginx.

Any help much appreciated.

docker-compose-local.yaml:

version: '3.10'

services:
  website:
    image: website_image_name
    build: .
    command: gunicorn -b 0.0.0.0:8000 app_name:app
    expose:
      - 8000
    env_file:
      - ./app.env


  dashboard:
    image: timh-urban-vprm-dashboard:latest
    command: mamba run --no-capture-output -n venv-urbanVPRM python urban_vprm_dashboard.py
    expose:
      - 8002
    ports:
      - 8002:8002

  nginx:
    image: nginx_image_name
    build: ./nginx
    ports:
      - 1337:80
    depends_on:
      - website
      - dashboard
    links:
      - website
      - dashboard

nginx.conf:

upstream site {
    server website:8000;
}

upstream dboard {
    server dashboard:8002;
}


server {

    listen 80;

    server_name 0.0.0.0;

    location / {
        proxy_pass http://site;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location /dboard/ {
        proxy_pass http://dboard;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}
0 Answers
Related