nginx-proxy and nginx-proxy-acme are two powerful tools that simplify the management of reverse proxies and SSL certificates for your Docker applications. These tools are particularly useful for those who host several applications on the same server and want to manage traffic routing and SSL certificates automatically. This article explores the main benefits of these tools and provides a detailed guide to installing and configuring them using Docker Compose.
Why choose Nginx-Proxy and Nginx-Proxy-Acme?
1. Simplified management of Reverse Proxies
nginx-proxy
makes it easy to manage multiple Docker applications using an Nginx reverse proxy. It automatically detects Docker containers and configures Nginx to redirect them according to domain headers.
2. Automatic SSL Certificates with LetsEncrypt
nginx-proxy-acme
is an add-on to nginx-proxy
that automates SSL certificate management with Let’s Encrypt. It automatically generates and renews SSL certificates, guaranteeing greater security without manual intervention.
3. Dynamic Configuration
Both tools use dynamic configuration to simplify the management of virtual hosts and SSL certificates. You don’t need to modify the Nginx configuration files manually every time you add or remove a container.
4. Open Source and Free
Both tools are open source and free, allowing you to use them, modify them and adapt them to your needs at no cost.
Installing Nginx-Proxy and Nginx-Proxy-Acme with Docker Compose
Installing nginx-proxy
and nginx-proxy-acme
via Docker Compose is simple. Here’s a step-by-step guide to configuring these tools on your server.
Prerequisites
Before you start, make sure that Docker and Docker Compose are installed on your server. You can install them using the following commands:
sudo apt update
sudo apt install docker.io docker-compose -y
Creating the Docker Compose file
Create a docker-compose.yml
file in a directory of your choice. This file will contain the configuration required to deploy nginx-proxy
and nginx-proxy-acme
. Use the following code to configure the services:
version: '3'
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx-proxy_conf:/etc/nginx/conf.d
- ./nginx-proxy_vhosts:/etc/nginx/vhost.d
- ./nginx-proxy_certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock
restart: always
nginx-proxy-acme:
image: nginxproxy/acme-companion
container_name: nginx-proxy-acme
volumes:
- ./nginx-proxy_certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock
environment:
- [email protected]
depends_on:
- nginx-proxy
restart: always
Explanations
- nginx-proxy:
- image: Indicates the official Docker image for
nginx-proxy
. - container_name: Name of the container for easy identification.
- ports: Maps container ports 80 and 443 to host ports 80 and 443 to manage HTTP and HTTPS traffic.
- volumes: Mounts the directories needed to store the Nginx configuration, certificate files and communication with the Docker socket.
- restart: Ensures that the container restarts automatically in the event of failure.
- nginx-proxy-acme:
- image: Indicates the official Docker image for
nginx-proxy-acme
. - container_name: Name of the container for easy identification.
- volumes: Mounts the directories needed to store SSL certificates and communication with the Docker socket.
- environment: Defines the email address for certificate renewal notifications.
- depends_on: Ensures that
nginx-proxy-acme
starts afternginx-proxy
.
Launch Services
Once you have created the docker-compose.yml
file, start the services with the following command:
sudo docker-compose up -d
This command downloads the Docker images, creates the containers, and starts nginx-proxy
and nginx-proxy-acme
in the background. The services will be automatically configured to handle HTTP and HTTPS requests for your Docker applications.
Configuring Docker Containers
For nginx-proxy
to manage Docker containers, you need to set the VIRTUAL_HOST
and LETSENCRYPT_HOST
environment variables in your other Docker services. Here is an example configuration for a Docker container:
version: '3'
services:
web:
image: your-web-app
environment:
- VIRTUAL_HOST=yourdomain.com
- LETSENCRYPT_HOST=yourdomain.com
- [email protected]
Conclusion
nginx-proxy
and nginx-proxy-acme
are powerful tools for managing reverse proxies and SSL certificates for your Docker applications. Thanks to their simple installation via Docker Compose and their ability to automate the management of SSL certificates, these tools make it much easier to administer your web services while ensuring greater security.
Useful links
- Official Nginx-Proxy website
- Nginx-Proxy GitHub repository
- Official website of Nginx-Proxy-Acme
- Nginx-Proxy-Acme GitHub repository
Share your experiences with nginx-proxy
and nginx-proxy-acme
and ask your questions in the comments section!