Question

Hosting Multiple Domains with SSL using Docker

I have been searching the web trying to figure how to host multiple domains (example1.com, example2.com, example3.com) with ssl using Docker. I have 3 domains I would like to host and some will have subdomains as well. At least one of them will be a Wordpress install and another a custom larval application.

I have came across articles/tutorials on doing this for subdomains using traefik or nginx but not multiple domains. Do I need a VPS for each domain?

Can anyone point me in the right direction.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey friend,

Great question. You do not need a separate server for each domain. Set aside the Docker/SSL thing for a moment, these will make more sense in the context of the most basic function for achieving the desired result.

When a user visits your domain they hit your web server, so that is the first need. The web server can then be configured to return different content based on the domain that they visited. This is called a Virtual Host in Apache, or a Server Block in Nginx. Each virtual host/server block configured in the web server can represent a different domain, or subdomain (whatever you need/prefer).

So regardless of whether or not you are using Docker, or simply a standalone web server outside of any Docker containers which redirects flow based on the requested domain, that web server must be listening on port 443 (for SSL, port 80 for non-SSL) and must be configured to serve content for that domain.

Personally, I use Caddy and I reverse proxy to ports that I’ve exposed from my Docker containers as needed. I just enjoy the syntax, for example:

hostname.tld {
        proxy / http://127.0.0.1:9000 {
                transparent
        }
}

Then “hostname.tld” returns the app listening on port 9000. The next block could be a copy/paste of that with “hostname2.tld” and port 9001, for example.

This can be accomplished with the applications of your choice, and there are many to choose from. I’m sure Traefik can accomplish this fine as well, it’s just not part of my personal workflow so it may require input from someone else.

Jarland

I ended up using Nginx Proxy by JWilder + LetsEncrypt Nginx Companion by jrcs

I understand everything you have said but I have a question about ssl.

Where would I apply my certs? Can I have 1 cert on caddy for all domains?(I’m guessing not) If I have ssl enabled from the container level, how would I handle containers for subdomains? I’m guessing they would use the same cert correct?