Manage a multiple websites server with Docker Compose, NGINX and auto SSL certificates
Tags: devops, docker, architecture, wordpress
Published: 2020-05-03 20:19:20

After my last post about deploying a [Vue application on Clever Cloud](https://dev.to/steeve/vuejs-app-on-clevercloud-https-redirection-in-few-minutes-gpf), 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 evertramos/docker-compose-letsencrypt-nginx-proxy-companion no-readme %}

The project creates a production environment in a few seconds. Everything is containerized. By looking at the [docker-compose.yml](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion/blob/master/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](https://github.com/evertramos/images/raw/master/webproxy.jpg)

The [setup](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion#how-to-use-it) is straightforward to understand, just clone the project and copy the example Dotenv file with a custom configuration. Finally, execute the script [`start.sh`](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion/blob/master/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:
```sh
VIRTUAL_HOST=your.domain.com
LETSENCRYPT_HOST=your.domain.com
LETSENCRYPT_EMAIL=your.email@your.domain.com
```
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: 
- Wordpress: [docker-wordpress-letsencrypt](https://github.com/evertramos/docker-wordpress-letsencrypt):
- Gitlab: [gitlab-docker-letsencrypt](https://github.com/steevepay/gitlab-docker-letsencrypt)
- [More...](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion#production-environment-using-web-proxy-and-wordpress)

## 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!