Skip to content

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

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:

  1. Create Directories:

    • Make directories for persistent data and Let's Encrypt certificates:
    mkdir /home/docker/nginx-proxy-manager/data
    
    mkdir /home/docker/nginx-proxy-manager/letsencrypt
    
  2. Create a Docker Compose File:

    • I typically place my yaml file in the /home/docker directory
    cd /home/docker/
    
    • Create the compose.yml file
    nano compose.yml
    

    -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

  1. Start Nginx Proxy Manager:

    • Navigate to the directory where your docker-compose.yml file is located and run the following command:
     cd /home/docker
    
     docker compose up -d
    
    • This command will download the necessary Docker images and start the Nginx Proxy Manager containers.
  2. Access the Web UI:

    • Open your browser and go to http://your-server-ip:81. For example, http://192.168.1.60:81.
      NGINX Proxy Manager
    • Log in with the default credentials (username: [email protected], password: changeme), and change the default password immediately.
      NGINX Proxy Manager

Step 3: Configure Port Forwarding on Your Router

  1. Login to Your Router:

    • Access your router's admin page by entering its IP address in your browser.
    • Navigate to the port forwarding section.
  2. 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:
      NGINX Proxy Manager
  3. Save the Configuration:

    • Save the changes and restart your router if necessary.

Step 4: Integrate with Cloudflare

Create an API Token

  1. Log in to Cloudflare:

    • Go to your Cloudflare dashboard and click on your profile icon on the top right corner.
      NGINX Proxy Manager
    • Select API Tokens from the dropdown menu.
      NGINX Proxy Manager
  2. Create an API Token:

    • Click on Create Token.
      NGINX Proxy Manager
    • Select the template Edit zone DNS.
    • Configure the permissions to allow editing DNS for your domain. NGINX Proxy Manager
    • Save the token and store it securely.
      NGINX Proxy Manager

Step 5: Configure SSL Certificates

  1. Log in to Nginx Proxy Manager:

    • Go to the SSL Certificates section.
    • Click on Add SSL Certificate.
      NGINX Proxy Manager
  2. 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. NGINX Proxy Manager
    • 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!