Install Nginx Proxy Manager on Ubuntu (+ Cloudflare)
Abstract
Nginx Proxy Manager is a user-friendly interface for managing Nginx reverse proxies. In this guide, I'll walk you through installing Nginx Proxy Manager on Ubuntu, integrating it with Cloudflare, and configuring SSL certificates.
Prerequisites
- Cloudflare account with domain name
- Ubuntu virtual machine
- Docker installed
Install Nginx Proxy Manager
Step 1: Prepare Docker Compose
First, we need to set up Docker Compose with a YAML configuration file for Nginx Proxy Manager. Follow these steps:
-
Create Directories:
- Make directories for persistent data and Let's Encrypt certificates:
-
Create a Docker Compose File:
- I typically place my yaml file in the /home/docker directory
- Create the compose.yml file
-Place in the docker compose yaml code below. The original source
services: nginx: image: 'jc21/nginx-proxy-manager:latest' restart: unless-stopped ports: # These ports are in format <host-port>:<container-port> - '80:80' # Public HTTP Port - '443:443' # Public HTTPS Port - '81:81' # Admin Web Port # Add any other Stream port you want to expose # - '21:21' # FTP #environment: # Uncomment this if you want to change the location of # the SQLite DB file within the container # DB_SQLITE_FILE: "/data/database.sqlite" # Uncomment this if IPv6 is not enabled on your host # DISABLE_IPV6: 'true' volumes: - /home/docker/nginx-proxy-manager/data:/data - /home/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt
- Exit the file (Ctrol + X)
Step 2: Initial Run
-
Start Nginx Proxy Manager:
- Navigate to the directory where your docker-compose.yml file is located and run the following command:
- This command will download the necessary Docker images and start the Nginx Proxy Manager containers.
-
Access the Web UI:
- Open your browser and go to http://your-server-ip:81. For example, http://192.168.1.60:81.
- Log in with the default credentials (username: [email protected], password: changeme), and change the default password immediately.
- Open your browser and go to http://your-server-ip:81. For example, http://192.168.1.60:81.
Step 3: Configure Port Forwarding on Your Router
-
Login to Your Router:
- Access your router's admin page by entering its IP address in your browser.
- Navigate to the port forwarding section.
-
Add Port Forwarding Rules:
- Forward external port 80 to internal port 80 on your server's IP address.
- Forward external port 443 to internal port 443 on your server's IP address.
- Below an example for a Unifi router:
-
Save the Configuration:
- Save the changes and restart your router if necessary.
Step 4: Integrate with Cloudflare
Create an API Token
-
Log in to Cloudflare:
- Go to your Cloudflare dashboard and click on your profile icon on the top right corner.
- Select API Tokens from the dropdown menu.
- Go to your Cloudflare dashboard and click on your profile icon on the top right corner.
-
Create an API Token:
- Click on Create Token.
- Select the template Edit zone DNS.
- Configure the permissions to allow editing DNS for your domain.
- Save the token and store it securely.
- Click on Create Token.
Step 5: Configure SSL Certificates
-
Log in to Nginx Proxy Manager:
- Go to the SSL Certificates section.
- Click on Add SSL Certificate.
-
Create a New SSL Certificate:
- Select Let's Encrypt and enter your domain details.
- Enable the option to use DNS challenge and enter your Cloudflare API token.
- Follow the prompts to complete the SSL certificate creation.
Conclusion
You have successfully installed Nginx Proxy Manager on Ubuntu, configured it with Cloudflare, and set up SSL certificates. You can now manage your reverse proxies through an easy-to-use web interface, ensuring your applications are secure and accessible.
For more detailed instructions and troubleshooting, refer to the Nginx Proxy Manager documentation. Happy proxying!