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
).
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
}