I use this project as my main reverse proxy for my server and it works great, but I have something that can't be run inside a docker container that I need to serve traffic to.
Is there anyway to do this? It's just a simple sumdomain.domain.com needs to go to some port on the host server.
You can achieve this by adding (with docker volumes) additional nginx config files into the nginx-proxy container as described in the documentation.
# mount this file as a volume in the nginx-proxy container under the
# /etc/nginx/conf.d/ folder:
#
# -v $(pwd)/subdomain.domain.com.conf:/etc/nginx/conf.d/zzzzz_subdomain.domain.com.conf:ro
#
# Make sure the conf file name in the container would be alphabetically
# sorted after the file named `default.conf`.
server {
server_name subdomain.domain.com;
listen 80;
location / {
proxy_pass https://11.22.33.44:1234/;
}
}
web1:
image: tutum/hello-world
environment:
VIRTUAL_HOST: web1.tld
web2:
image: tutum/hello-world
environment:
VIRTUAL_HOST: web2.tld
nginxproxy:
image: jwilder/nginx-proxy
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./subdomain.domain.com.conf:/etc/nginx/conf.d/zzzzz_subdomain.domain.com.conf:ro
ports:
- 80:80
# docker-compose up -d
# curl http://localhost/ -H "Host: web1.tld"
# curl http://localhost/ -H "Host: web2.tld"
# curl http://localhost/ -H "Host: subdomain.domain.com"
Note that if the port on your docker host you want to reach from http://subdomain.domain.com is bound to 127.0.0.1 you are screwed, as from the nginx-proxy container perspective 127.0.0.1 would be the nginx-proxy container itself.
Perfect, thanks for the advice, works like a charm!
Hi Guys: I'm hoping based on discussion above to get some help. I'm trying to use nginx reverse proxy (eventually over ssl) out in front of upstream nginx containers each with a unique subdomain for a web app. Initially, I'm leaving out the ssl parts, trying simply to have nginx as reverse proxy aimed at upstream nginx containers with subdomains. So for initial tests, I'm aiming at being able to go to "http://subdomain.mydomain.dyndns.org" to get to each particular upstream instance. I've assumed I need to load in nginx.conf as a volume (see below) in the reverse-proxy to make this all go,
While I can get to the proxy, I can't get at the subdomain upstream containers (inside or outside my firewall). Q: do I need to do something in the hosts file or resov.conf to make subdomains work, or is this all wrong for my use case? For development purposes, I'm using a dyndns address for now on a home server. Some of my code:
1) docker-compose.yml
version: '3.1'
services:
nginx-proxy:
container_name: nginxproxy
image: jwilder/nginx-proxy
ports:
- "80:80"
dns_search:
- "mydomain.dyndns.org"
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "./nginx.conf:/etc/nginx/nginx.conf"
test:
container_name: test
image: nginx:latest
environment:
- VIRTUAL_HOST=test.mydomain.dyndns.org
2) The server block of the nging.conf is:
server {
listen 500 default_server;
server_name test.mydomain.dyndns.org;
location /
proxy_pass http://192.168.1.99:500;
proxy_set_header Host 192.168.1.99:500;
}
}
upstream main {
server 192.168.1.99:500;
}
server {
listen 80;
server_name mydomain.dyndns.org;
}
The containers start and stay up. I have tried fiddling with various alternatives in the nginx directives (and tried loading a nginx.conf for the upstream), but consistently connect to the reverse-proxy but not the subdomain. Thoughts? Thx!
I use the qoomon/docker-host image for that, which creates a container doing nothing else than mapping a host port.
In docker-compose you can do something like:
mapport3000:
image: qoomon/docker-host # this proxies to the host machine
restart: always
cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
ports:
- 3000
environment:
- VIRTUAL_HOST=xxx
- LETSENCRYPT_HOST=xxx
- LETSENCRYPT_EMAIL=xxx
Most helpful comment
You can achieve this by adding (with docker volumes) additional nginx config files into the nginx-proxy container as described in the documentation.
subdomain.domain.com.conf
docker-compose.yml
start the containers
test
Note that if the port on your docker host you want to reach from http://subdomain.domain.com is bound to
127.0.0.1you are screwed, as from the nginx-proxy container perspective127.0.0.1would be the nginx-proxy container itself.