Set up NGINX as a proxy for your Docker containers
Recently I’m a fan of serving docker containers over serving Virtual Hosts using a webserver.
In order to use regular domainnames without ports, I set up Nginx to receive the request on the domainname and let it forward the request to the relevant Docker container on the specific port it is running on.
Example
Imagine I have a Docker webserver-container hosting my app. It runs on my server exposing port 8080. I use the URL app.pauledenburg.com
.
I don’t want people to use http://app.pauledenburg.com:8080
but just the URL without the port
http://app.pauledenburg.com
.
I use nginx for this:
server { listen 80; server_name app.pauledenburg.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }