Manage a multiple websites server with Docker Compose, NGINX and auto SSL certificates

Steeve - May 3 '20 - - Dev Community

After my last post about deploying a Vue application on Clever Cloud, I have been thinking to manage a server and deploy all my side projects on it. The goal was to:

  • set up a reverse proxy easily
  • automatically generate/renew the SSL certificates (let's encrypt)
  • few simple configurations

One project caught my eye on Github:

GitHub logo evertramos / nginx-proxy-automation

Automated docker nginx proxy integrated with letsencrypt.

The project creates a production environment in a few seconds. Everything is containerized. By looking at the docker-compose.yml, the environment is based on 3 main containers:

  • nginx-web: NGINX reverse proxy server and web server, it distributes requests to the corresponding container.
  • nginx-gen: It generates the vhost configurations and detects if running containers are started or stopped to reloads NGINX.
  • nginx-letsencrypt: Automated creation/renewal of Let's Encrypt certificates

Here is a simplified schema:

docker compose letsencrypt nginx proxy schema

The setup is straightforward to understand, just clone the project and copy the example Dotenv file with a custom configuration. Finally, execute the script start.sh to pull the images and run the containers.

To make an application available on the web, the container has to be connected to the webproxy network and needs 3 environment variables:

VIRTUAL_HOST=your.domain.com
LETSENCRYPT_HOST=your.domain.com
LETSENCRYPT_EMAIL=your.email@your.domain.com
Enter fullscreen mode Exit fullscreen mode

Configure the DNS provider to point your.domain.com to the server IP. Start the container and that's it! Visit the web application at the specified domain name.

As an example, the following projects can be created in few second:

Conclusion

The project docker-compose-letsencrypt-nginx-proxy-companion is maybe not the best option for a big production with hundreds of thousands of users (I have never tried). Nevertheless, it is working perfectly for small applications. It is easy to set up and trustworthy. A small community is available and the creator is reactive on Github.

For now, this project is a good solution for me to serve all my projects on the web at a low cost. I'm pretty happy to use it!

How do you manage your server and projects?

Thanks for reading!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .