In case someone is still looking for an answer. jwilder / nginx-proxy allows you to use the custom Nginx configuration for both the entire proxy and per VIRTUAL_HOST.
Here's how you can do this using the Per-VIRTUAL_HOST location configuration.
- Inside your project folder, create another folder - "vhost.d".
- Create a file "whoami.local" with the user configuration nginx inside the folder "vhost.d". This file must have the same name as VIRTUAL_HOST!
./vhost.d/whoami.local
location /app1 { proxy_pass http://app1:8000; } location /app2 { proxy_pass http://app2:8000; }
- Create a docker-compose.yml file.
./docker-compose.yml
version: '3' services: nginx-proxy: image: jwilder/nginx-proxy ports: - "8080:80" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - /path/to/vhost.d:/etc/nginx/vhost.d:ro gateway: image: jwilder/whoami environment: - VIRTUAL_HOST=whoami.local app1: image: jwilder/whoami app2: image: jwilder/whoami
- Run docker-compose up
- Check configuration
In bash run:
$ curl -H "Host: whoami.local" localhost:8080 I'm 1ae273bce7a4 $ curl -H "Host: whoami.local" localhost:8080/app1 I'm 52b1a7b1992a $ curl -H "Host: whoami.local" localhost:8080/app2 I'm 4adbd3f9e7a0 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a659a4d4b0a jwilder/nginx-proxy "/app/docker-entrypo…" 54 seconds ago Up 53 seconds 0.0.0.0:8080->80/tcp nginxreverseproxy_nginx-proxy_1 4adbd3f9e7a0 jwilder/whoami "/app/http" 54 seconds ago Up 53 seconds 8000/tcp nginxreverseproxy_app2_1 52b1a7b1992a jwilder/whoami "/app/http" 54 seconds ago Up 53 seconds 8000/tcp nginxreverseproxy_app1_1 1ae273bce7a4 jwilder/whoami "/app/http" 54 seconds ago Up 53 seconds 8000/tcp nginxreverseproxy_gateway_1
You can also add the "whoami.local" domain to the / etc / hosts file and directly call this domain.
/ etc / hosts
... 127.0.0.1 whoami.local ...
Result:
$ curl whoami.local:8080 I'm 52ed6da1e86c $ curl whoami.local:8080/app1 I'm 4116f51020da $ curl whoami.local:8080/app2 I'm c4db24012582
source share