Like many digital builders/hackers/makers, I have several projects that I want to put on the internet. I don't, however, want to have loads of servers to manage. Given that the highest-traffic project I maintain only around 100 unique visitors a day, it's feasible for me to host them all on the same node.
I already deploy these things in Docker containers, so I imagined I could use nginx to solve this problem. It would work, I imagined, by having a single Docker host running an nginx container that would reverse proxy requests to other containers (which would be running the aforementioned projects). When I started researching how to do this, I found a great project that made it super easy.
Jason Wilder has a great
that you should read if you want more detail, but the gist is that
jwilder/nginx-proxy is an nginx
container that proxies to other containers. It automatically configures nginx
based on the
EXPOSEd ports of the containers you're running, which is almost
Start it up like this:
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock -t jwilder/nginx-proxy
You can make this even cooler with a bit of fiddling with your DNS records. Add an A record that points to the Docker host, then add a wildcard CNAME that points to the URL you set up in the A record (see screenshot below for how I have it set up).
(where "184.108.40.206" is the IP of your Docker host)
Now, you can start up a container with a
VIRTUAL_HOST environment variable
that is in that subdomain:
docker run -e 'VIRTUAL_HOST=rss.project.samueltaylor.org' -tid ssaamm/rss_filter
When you navigate to this URL, your browser will ask your nginx container for the site at that URL, and that container will know to reverse proxy the request to the container you just started. Nifty!
Please reach out if you have any questions or want to get in touch! My email address is sgt at this domain.