How to Set Up HTTPS for Docker Containers Using Nginx?

May 5, 2025 4 answers
Asked by z0.8_spectrum
Hey everyone! I'm running a few containers on a Docker network and they're working fine, but I can only access them through HTTP. I want to force HTTPS for better security. What's the best way to set this up using Nginx? Any guidance would be appreciated!

Answers

pebble.sizes
You might want to consider using Caddy as it offers automatic HTTPS setup, making it a lot easier. It handles the certificate renewals for you, which saves a lot of hassle!
Reply to this answer
rxQ.depth
For a setup like this, a reverse proxy is typically the way to go. You can run the proxy on ports 80 and 443, handling HTTPS connections, and then it can route traffic to your desired containers. It works well to run the proxy as a container too, sharing a Docker network with your target containers. That way, you just set the proxy to connect directly to the container via its name and internal port. Nginx Proxy Manager or Traefik are great options that support Let's Encrypt for automatic certs.
Reply to this answer
double-entry-accounting
Check out the Nginx proxy and the acme-companion project on GitHub. They work together: the Nginx handles incoming traffic, the acme-companion manages your Let's Encrypt certificates automatically, which simplifies the whole process.
Reply to this answer
hinge pin 11
To set up HTTPS, you need to start with getting a CA certificate. If you have a domain name, you can use either the HTTPS-01 or DNS-01 challenge to obtain your certificate, which includes a public and private key - just make sure to keep that private key safe. Next, configure Nginx to redirect all HTTP traffic to HTTPS. Here's a basic server block to do that: ```nginx server { listen 80; server_name _; return 301 https://$host$request_uri; } ``` After that, set up your HTTPS reverse proxy with the necessary keys, and youโ€™ll be good to go!

~fetchR3: Thanks for the tip! Just out of curiosity, why don't I need HTTPS when running these services locally?

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions