Nginx Proxy Manager is a simple and powerful tool that provides a web-based interface for managing Nginx reverse proxies, making it easy to set up SSL certificates and manage multiple services.
If you don't already have Docker installed, follow the instructions on Docker’s website.
For Docker Compose, you can check if it's installed by running:
docker-compose --version
If not installed, install it by following the official guide here.
Open a terminal and create a new directory to store the Docker Compose configuration:
mkdir nginx-proxy-manager
cd nginx-proxy-manager
docker-compose.yml
FileInside the nginx-proxy-manager
directory, create a new file named docker-compose.yml
:
touch docker-compose.yml
Open the file with a text editor and add the following configuration:
version: '3'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80' # HTTP
- '81:81' # Admin Panel
- '443:443' # HTTPS
environment:
DB_MYSQL_HOST: "db"
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: "npm"
DB_MYSQL_PASSWORD: "npm_password"
DB_MYSQL_NAME: "npm"
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
db:
image: 'mysql:5.7'
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: 'root_password'
MYSQL_DATABASE: 'npm'
MYSQL_USER: 'npm'
MYSQL_PASSWORD: 'npm_password'
volumes:
- ./mysql:/var/lib/mysql
Here’s what this configuration does:
app
: This is the Nginx Proxy Manager container.db
: A MySQL 5.7 container to handle the database for Nginx Proxy Manager.80:80
: Maps port 80 for HTTP traffic.81:81
: Maps port 81 for accessing the Nginx Proxy Manager admin web interface.443:443
: Maps port 443 for HTTPS traffic../data:/data
: Stores Nginx Proxy Manager data on your local machine../letsencrypt:/etc/letsencrypt
: Stores Let's Encrypt SSL certificates../mysql:/var/lib/mysql
: Stores MySQL database files.Ensure you’re in the nginx-proxy-manager
directory where your docker-compose.yml
file is located.
Run the following command to start the containers:
docker-compose up -d
up
: This starts the services defined in your docker-compose.yml
.-d
: Runs the services in detached mode (in the background).Docker Compose will download the required images (if they aren’t already present) and start both the Nginx Proxy Manager and MySQL containers.
Open a web browser and navigate to:
http://localhost:81
You’ll see the Nginx Proxy Manager login page. Use the following default credentials:
admin@example.com
changeme
After logging in, change the admin email and password to something secure.
http://your-app:3000
, enter your-app.local
.your-app
.3000
for a service running on port 3000).https://your-domain.com
.You can continue to manage your proxy hosts, SSL certificates, and advanced Nginx configurations from the Nginx Proxy Manager admin interface. It also allows you to:
Let’s say you’re running a web app locally on port 8080 and want to access it via myapp.local
. You’d follow these steps:
Add myapp.local
to your computer’s hosts
file, pointing to 127.0.0.1
:
127.0.0.1 myapp.local
In Nginx Proxy Manager, add a new proxy host:
myapp.local
127.0.0.1
8080
After configuring the proxy host, open your browser and visit http://myapp.local
to see the application.
To stop the Nginx Proxy Manager containers, run:
docker-compose down
This will stop and remove both the Nginx Proxy Manager and MySQL containers, but your data will remain in the volumes (./data
, ./letsencrypt
, and ./mysql
).
Traefik is a powerful and modern reverse proxy that integrates easily with Docker and other orchestrators. It automatically manages services, handles dynamic routing, and supports features like HTTPS and load balancing.
docker-compose --version
If it's not installed, follow the guide here.mkdir traefik-setup
cd traefik-setup
traefik.toml
Configuration FileInside the traefik-setup
directory, create a new directory for the Traefik configuration files:
mkdir config
Create the traefik.toml
file inside the config
directory:
touch config/traefik.toml
Open traefik.toml
in a text editor and add the following content:
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.websecure]
address = ":443"
[api]
dashboard = true
insecure = true
[providers]
[providers.docker]
endpoint = "unix:///var/run/docker.sock"
exposedByDefault = false
Here's what the configuration does:
:80
) and HTTPS (:443
).docker-compose.yml
FileIn the traefik-setup
directory, create a file named docker-compose.yml
:
touch docker-compose.yml
Open docker-compose.yml
in a text editor and add the following configuration:
version: '3'
services:
traefik:
image: traefik:v2.9
container_name: traefik
restart: unless-stopped
ports:
- "80:80" # HTTP
- "443:443" # HTTPS
- "8080:8080" # Traefik Dashboard
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Give Traefik access to Docker
- ./config/traefik.toml:/etc/traefik/traefik.toml # Traefik configuration file
networks:
- web
networks:
web:
external: true
Explanation:
traefik
: This is the Traefik service that uses the official Traefik Docker image.80
: Exposes HTTP traffic.443
: Exposes HTTPS traffic.8080
: Exposes the Traefik dashboard./var/run/docker.sock
: Grants Traefik access to the Docker socket for service discovery../config/traefik.toml
: Links the local Traefik configuration file to the container.web
. This allows other services to connect to Traefik using Docker networking.web
:docker network create web
Make sure you're in the traefik-setup
directory where the docker-compose.yml
file is located.
Run the following command to start Traefik using Docker Compose:
docker-compose up -d
up
: Starts the containers defined in your docker-compose.yml
.-d
: Runs the containers in detached mode (in the background).Docker Compose will download the Traefik image (if it’s not already present) and start the Traefik container.
http://localhost:8080
Now, let’s deploy a simple web service (such as an Nginx container) and expose it through Traefik.
Create a directory for the sample service:
mkdir nginx
cd nginx
Create a docker-compose.yml
file for the Nginx service:
touch docker-compose.yml
Add the following content to docker-compose.yml
:
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.rule=Host(`nginx.local`)"
- "traefik.http.services.nginx.loadbalancer.server.port=80"
networks:
- web
restart: unless-stopped
networks:
web:
external: true
nginx
: This is the Nginx container."traefik.enable=true"
: Enables Traefik routing for this service."traefik.http.routers.nginx.rule=Host('nginx.local')"
: Defines the routing rule (based on the hostname nginx.local
)."traefik.http.services.nginx.loadbalancer.server.port=80"
: Specifies the internal port that Nginx is using.web
network, shared with Traefik.nginx.local
to Your hosts
FileTo access nginx.local
from your browser, add it to your local hosts
file.
For Linux and MacOS, open /etc/hosts
and add the following line:
127.0.0.1 nginx.local
For Windows, edit the C:\Windows\System32\drivers\etc\hosts
file similarly.
In the nginx
directory, start the Nginx service with Docker Compose:
docker-compose up -d
Open your browser and navigate to:
http://nginx.local
You should see the default Nginx welcome page, confirming that Traefik is successfully routing traffic to your Nginx container.
To enable HTTPS with Let's Encrypt, update the traefik.toml
configuration to include Let's Encrypt settings.
Edit config/traefik.toml
and add the following:
[certificatesResolvers]
[certificatesResolvers.le.acme]
email = "your-email@example.com"
storage = "/etc/traefik/acme.json"
[certificatesResolvers.le.acme.httpChallenge]
entryPoint = "web"
This tells Traefik to use Let's Encrypt and store certificates in /etc/traefik/acme.json
.
Create an empty acme.json
file and set the correct permissions:
touch config/acme.json
chmod 600 config/acme.json
Update your Nginx service’s Docker Compose labels to enable HTTPS:
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.rule=Host(`nginx.local`)"
- "traefik.http.services.nginx.loadbalancer.server.port=80"
- "traefik.http.routers.nginx.entrypoints=web"
- "traefik.http.routers.nginx-secure.rule=Host(`nginx.local`)"
- "traefik.http.routers.nginx-secure.entrypoints=websecure"
- "traefik.http.routers.nginx-secure.tls.certresolver=le"
Restart Traefik and the Nginx service to apply the changes:
docker-compose restart
Visit https://nginx.local
to see the Nginx page served over HTTPS.
Traefik is a modern, dynamic reverse proxy and load balancer for microservices and containerized applications, often used with Docker, Kubernetes, or other orchestration systems.
docker --version
docker-compose --version
mkdir traefik
cd traefik
docker-compose.yml
FileInside the traefik
directory, create a docker-compose.yml
file:
touch docker-compose.yml
Open the docker-compose.yml
file in your favorite text editor and add the following configuration:
version: '3.8'
services:
traefik:
image: traefik:v2.10
container_name: traefik
restart: unless-stopped
command:
- "--api.insecure=true" # Enables the Traefik dashboard (insecure for testing)
- "--providers.docker=true" # Enable Docker as a provider
- "--entryPoints.web.address=:80" # Define the HTTP entry point
- "--entryPoints.websecure.address=:443" # Define the HTTPS entry point
ports:
- "80:80" # HTTP port
- "443:443" # HTTPS port
- "8080:8080" # Traefik dashboard port
volumes:
- "/var/run/docker.sock:/var/run/docker.sock" # Allows Traefik to interact with Docker
labels:
- "traefik.enable=true" # Enables Traefik for this container
# Example Web Application (to demonstrate Traefik in action)
whoami:
image: traefik/whoami
container_name: whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.local`)" # Router rule for this service
- "traefik.http.services.whoami.loadbalancer.server.port=80" # Port for the service
Traefik Service:
traefik:v2.10
image.--api.insecure=true
command enables the Traefik dashboard (though insecure, it’s fine for a test environment).--providers.docker=true
, meaning Traefik will discover containers automatically./var/run/docker.sock
) to interact with Docker.Whoami Service:
Host
rule is set to route requests for whoami.local
to this container.Make sure you are inside the directory where your docker-compose.yml
file is located.
Run the following command to start Traefik and the example service (whoami
):
docker-compose up -d
up
: Starts the containers defined in docker-compose.yml
.-d
: Runs the containers in detached mode.Docker will pull the necessary images (if they’re not already present) and start both the Traefik and whoami containers.
Open your browser and go to the following URL to access the Traefik dashboard:
http://localhost:8080
You should see the Traefik dashboard showing the whoami container as a service.
To test the proxy, you need to edit your system’s hosts
file to point whoami.local
to 127.0.0.1
(localhost).
On Linux or MacOS:
sudo nano /etc/hosts
Add the following line:
127.0.0.1 whoami.local
On Windows, you can edit the hosts
file located at C:\Windows\System32\drivers\etc\hosts
and add:
127.0.0.1 whoami.local
After saving the hosts
file, open a web browser and visit:
http://whoami.local
You should see the response from the whoami container, showing basic information about the request (like headers, IP, etc.).
You can add more services to the docker-compose.yml
file and manage them with Traefik in a similar way. Here's an example of adding another service:
example:
image: httpd:alpine
container_name: example
labels:
- "traefik.http.routers.example.rule=Host(`example.local`)"
- "traefik.http.services.example.loadbalancer.server.port=80"
After adding this service, don't forget to update the hosts
file again:
127.0.0.1 example.local
Visit http://example.local
to see the new service.
To stop the containers, use the following command:
docker-compose down
This will stop and remove the containers but leave the volumes intact (for data persistence).
docker-compose.yml
FileHere’s an example of a more complete docker-compose.yml
with multiple services:
version: '3.8'
services:
traefik:
image: traefik:v2.10
container_name: traefik
restart: unless-stopped
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entryPoints.web.address=:80"
- "--entryPoints.websecure.address=:443"
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
whoami:
image: traefik/whoami
container_name: whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.local`)"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
example:
image: httpd:alpine
container_name: example
labels:
- "traefik.http.routers.example.rule=Host(`example.local`)"
- "traefik.http.services.example.loadbalancer.server.port=80"
Caddy is a modern web server that automatically provisions SSL certificates using Let's Encrypt, which makes it very easy to set up secure HTTPS servers.
docker --version
docker-compose --version
mkdir caddy-docker
cd caddy-docker
docker-compose.yml
FileInside the caddy-docker
directory, create a docker-compose.yml
file:
touch docker-compose.yml
Open the docker-compose.yml
file in your preferred text editor and add the following configuration:
version: '3.8'
services:
caddy:
image: caddy:latest
container_name: caddy
restart: unless-stopped
ports:
- "80:80" # HTTP port
- "443:443" # HTTPS port
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile # Mount the Caddyfile configuration
- ./data:/data # To store certificates
- ./config:/config # Configuration data
environment:
- ACME_AGREE=true # Automatically accept the Let's Encrypt terms
networks:
- caddy_network
whoami:
image: traefik/whoami
container_name: whoami
labels:
- "traefik.enable=false" # Disable Traefik routing for this container
networks:
- caddy_network
networks:
caddy_network:
driver: bridge
Caddy Service:
caddy:latest
Docker image.Caddyfile
configuration file to /etc/caddy/Caddyfile
in the container.data
volume for storing SSL certificates, so they persist across container restarts.ACME_AGREE=true
to automatically accept the Let's Encrypt terms.Whoami Service:
traefik.enable=false
.Networks:
caddy_network
), allowing Caddy to route traffic to whoami
.Inside the same caddy-docker
directory, create a Caddyfile
to configure how Caddy should handle incoming traffic. This is where you’ll define routing rules, domains, and SSL configurations.
touch Caddyfile
Open the Caddyfile
in your text editor and add the following content:
whoami.local {
reverse_proxy whoami:80
}
This configuration tells Caddy to listen for requests to whoami.local
and reverse proxy those requests to the whoami service running on port 80
.
Important: The
whoami.local
domain will need to be added to your system'shosts
file for it to resolve locally.
Make sure you are in the directory where the docker-compose.yml
and Caddyfile
are located.
Run the following command to start the services in detached mode:
docker-compose up -d
up
: Starts the containers defined in docker-compose.yml
.-d
: Runs the containers in detached mode (in the background).Docker will pull the necessary images and start both the Caddy and whoami containers.
hosts
FileTo access the whoami.local
domain, you need to modify your system's hosts
file so that whoami.local
points to 127.0.0.1
(localhost).
On Linux or MacOS:
hosts
file with a text editor:sudo nano /etc/hosts
127.0.0.1 whoami.local
On Windows:
hosts
file located at C:\Windows\System32\drivers\etc\hosts
in a text editor (run as Administrator).127.0.0.1 whoami.local
Open your browser and navigate to:
http://whoami.local
You should see the response from the whoami container, which will display basic information about the HTTP request (such as headers, IP, etc.).
Caddy automatically provisions an SSL certificate for your domain through Let's Encrypt. To access your service securely, visit:
https://whoami.local
Caddy will automatically handle the HTTPS configuration, and your connection will be encrypted.
To stop and remove the containers, run the following command:
docker-compose down
This stops the containers and removes them, but it retains the data and configuration for the next time you bring the containers back up.
If you made changes to the Caddyfile
or want to restart the services, you can run:
docker-compose restart
This restarts the containers without removing them.
docker-compose.yml
and Caddyfile
Here’s the final version of the docker-compose.yml
and Caddyfile
:
docker-compose.yml
:
version: '3.8'
services:
caddy:
image: caddy:latest
container_name: caddy
restart: unless-stopped
ports:
- "80:80" # HTTP port
- "443:443" # HTTPS port
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./data:/data
- ./config:/config
environment:
- ACME_AGREE=true
networks:
- caddy_network
whoami:
image: traefik/whoami
container_name: whoami
labels:
- "traefik.enable=false"
networks:
- caddy_network
networks:
caddy_network:
driver: bridge
Caddyfile
:
whoami.local {
reverse_proxy whoami:80
}