Setup HTTP(s) and Reverse Proxy to Docker Web App
This article is about how to add https to a web app running in docker. For this we are using nginx to handle port 80 and port 443 and then reverse proxy the traffic to port 443 to the application port. In this article we are assuming you have credentials for the SSL certificate, another article will be written on how to do it with lets encrypt to create ssl certificates for free.
This article assume you know about ssl key files, docker and docker-compose. And for the sake of this article we are setting up uptime-kuma
.
To start you create a nginx.conf
file:
|
|
After you create the nginx.conf and place it in the same folder as your docker-compose. Create a folder called ssl_keys and place your ssl_certificate
and ssl_private_key
in a folder called ssl_keys
. Once that is done, add the following configuration to your docker-compose.yml
|
|
What happening above is that we are putting both containers on a same network (virtual) called reverse-proxy-network
. Nginx which is running on one container redirecting all the traffic to port 80 to port 443, thus enforcing https. And the traffic 443 is reverse proxies to port 3001. Uptime-kuma doesn’t need to run SSL mode, nginx is now ensuring the traffic to the server is encrypted and then sending the decrypted traffic to uptime-kuma
container.