Reverse proxy for local dns resolving
Aug 16, 2020
I have a bunch of services running in my home network. The more services I add, the more trouble I have remembering the ports for everything. Running a reverse proxy was something that has been on my planning for a while now but never got to implementing.
That was until last week when I learned about jwilder/nginx-proxy.
TLDR; it auto generates a reverse proxy configuration for nginx based on the running containers in your docker environment. The only thing you have to do is set two environment variables VIRTUAL_HOST
and VIRTUAL_PORT
on whatever container you like to specify the dns record and port it should forward to.
Example docker-compose.yml
config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
version: '3' services: nginx-proxy: image: jwilder/nginx-proxy ports: - 80:80 volumes: - /var/run/docker.sock:/tmp/docker.sock:ro environment: DEFAULT_HOST: whoami.local whoami: image: jwilder/whoami environment: VIRTUAL_HOST: whoami.local
What's left for us to do is point our local DNS server to resolve everything ending in .local
to our host running the reverse proxy. In my case (and as you can read in my previous post here) I have a dnsmasq server running. To set it up with the reverse proxy I just have to add the following line to my dnsmasq.conf
:
address=/local/10.0.0.123 # Your hosts IP address
This will redirect all domain names ending in .local
to the host at IP 10.0.0.123, which will then get forwarded to the correct IP/container by the jwilder/nginx-proxy
container.
That's literally the only thing you have to do. It will generate an internal proxy_pass
configuration that will resolve whoami.local
to the container whoami
🚀