Reverse proxy for local dns resolving

Sun 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:

1version: '3' 2 3services: 4 nginx-proxy: 5 image: jwilder/nginx-proxy 6 ports: 7 - 80:80 8 volumes: 9 - /var/run/docker.sock:/tmp/docker.sock:ro 10 environment: 11 DEFAULT_HOST: whoami.local 12 13 whoami: 14 image: jwilder/whoami 15 environment: 16 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:

1address=/local/ # Your hosts IP address

This will redirect all domain names ending in .local to the host at IP, 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 🚀