0

I'm attempting to use "Path-based routing" on an nginx-proxy docker-compose project.

The goal is to have container "va-web" handle HTTP requests to "http://varitest.com/" and container "va-web-apps" handle requests to "http://varitest.com/app"

Using this docker-compose.yml setup:

version: '2'
services:
  nginx-p2:
    image: nginxproxy/nginx-proxy
    container_name: nginx-p2
    restart: no
    ports:
      - "80:80"
    volumes:
      - conf:/etc/nginx/conf.d
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro

  va-web:
    image: nginx
    container_name: va-web
    restart: no
    volumes:
      - ./va-web:/usr/share/nginx/html
    environment:
      - VIRTUAL_HOST=varitest.com
      - VIRTUAL_PATH=/

  va-web-apps:
    image: nginx
    container_name: va-web-apps
    restart: no
    volumes:
      - ./va-web-apps:/usr/share/nginx/html
    environment:
      - VIRTUAL_HOST=varitest.com
      - VIRTUAL_PATH=/app

volumes:
  conf:
  vhost:
  html:

The resulting nginx default.conf looks like this: (I've cut out the unrelated SSL stuff for brevity)

server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    listen 80;
    access_log /var/log/nginx/access.log vhost;

    return 503;
}
# varitest.com/app
upstream varitest.com-0c35eebf403cf91fe77a64921d76aa1ca6411d20 {
    server 172.18.0.2:80;
}
server {
    server_name varitest.com;
    access_log /var/log/nginx/access.log vhost;
    listen 80 ;

    location /app {
        proxy_pass http://varitest.com-0c35eebf403cf91fe77a64921d76aa1ca6411d20;
        set $upstream_keepalive false;
    }
    location / {
        return 404;
    }
}

... which doesn't look right and any request to any URL on varitest.com results in a 404.

Stopping service/container "va-web-apps" results in a nginx default.conf like this: (which works fine)

server {
    server_name _; # This is just an invalid value which will never trigger on a real hostname.
    server_tokens off;
    listen 80;
    access_log /var/log/nginx/access.log vhost;

    return 503;
}
# varitest.com/
upstream varitest.com {
    server 172.18.0.3:80;
}
server {
    server_name varitest.com;
    access_log /var/log/nginx/access.log vhost;
    listen 80 ;

    location / {
        proxy_pass http://varitest.com;
        set $upstream_keepalive false;
    }
}

What am I doing wrong with my docker-compose.yml with respect to using Path-based routing?

Baker
  • 24,730
  • 11
  • 100
  • 106

0 Answers0