What is Nginx Proxy Manager?

Nginx Proxy Manager (NPM) is a web-based interface for managing Nginx reverse proxy servers. It simplifies the process of setting up and managing proxy hosts, SSL certificates, redirections, and access control. NPM is particularly user-friendly for those who may not be familiar with configuring Nginx manually, offering a graphical interface to handle complex configurations easily.

Key Features of Nginx Proxy Manager

  1. Proxy Hosts: Create and manage multiple proxy hosts for routing traffic.
  2. SSL Certificates: Easily obtain and manage Let’s Encrypt SSL certificates.
  3. Redirection: Set up HTTP to HTTPS redirection and custom domain redirections.
  4. Access Lists: Control access to certain services based on IP addresses.
  5. Websocket Support: Handle WebSocket connections with ease.
  6. User-Friendly Interface: Intuitive UI for managing your proxies and settings.

Installing Nginx Proxy Manager

Requirements

  • A server running Docker and Docker Compose.
  • Basic knowledge of terminal commands.
  • A domain name pointing to your server’s IP address.

Step-by-Step Installation

  1. Install Docker and Docker Compose: If not already installed, use the following commands to install Docker on your server:

    sudo apt update
    sudo apt install docker.io docker-compose
    
  2. Create a Docker Network: This is optional but recommended for better organization:

    docker network create nginx-proxy
    
  3. Create a Docker Compose File: Create a new directory for Nginx Proxy Manager and navigate into it:

    mkdir nginx-proxy-manager
    cd nginx-proxy-manager
    

    Create a docker-compose.yml file:

    version: '3'
    
    services:
      app:
        image: jc21/nginx-proxy-manager:latest
        restart: unless-stopped
        ports:
          - '80:80'
          - '81:81'   # Admin interface
          - '443:443'
        volumes:
          - ./data:/data
          - ./letsencrypt:/etc/letsencrypt
        environment:
          DB_MYSQL_HOST: db
          DB_MYSQL_USER: npm
          DB_MYSQL_PASSWORD: npm
          DB_MYSQL_NAME: npm
          TZ: "Europe/London"
    
      db:
        image: jc21/mariadb:latest
        restart: unless-stopped
        volumes:
          - ./data/mysql:/var/lib/mysql
        environment:
          MYSQL_ROOT_PASSWORD: npm
          MYSQL_DATABASE: npm
          MYSQL_USER: npm
          MYSQL_PASSWORD: npm
    
  4. Start Nginx Proxy Manager: Run the following command to start the services:

    docker-compose up -d
    
  5. Access the Nginx Proxy Manager Interface: Open a web browser and navigate to http://<your-server-ip>:81. Log in using the default credentials:

    • Email: admin@example.com
    • Password: changeme

    Make sure to change the default password upon first login.

Setting Up Proxy Hosts

  1. Adding a New Proxy Host:

    • Click on Proxy Hosts in the dashboard.
    • Click on Add Proxy Host.
    • Enter your domain name (e.g., example.com).
    • Specify the scheme (HTTP/HTTPS) and the IP address of the service you want to proxy to.
    • Under Advanced, you can add custom Nginx configurations if needed.
  2. Setting Up SSL:

    • In the SSL tab, check Block Common Exploits and Force SSL.
    • Choose Request a new SSL certificate and enter your email address for Let’s Encrypt notifications.
    • Click Save to apply changes.

Redirecting www to Non-www

To set up redirection from www to non-www, you can follow these steps:

Method 1: Using Proxy Hosts

  1. Add a Proxy Host for the www Domain:

    • Go to Proxy Hosts and click Add Proxy Host.
    • For the Domain Names, enter www.example.com.
    • Set the scheme to HTTP or HTTPS depending on your configuration.
    • In the Advanced tab, add the following configuration:
      return 301 $scheme://example.com$request_uri;
      
    • Save the configuration.
  2. Ensure SSL is Configured for Both Domains:

    • Make sure both the www and non-www domains have valid SSL certificates set up.

Method 2: Using Cloudflare Page Rules

If you are using Cloudflare, you can manage the redirection directly through Cloudflare’s page rules.

  1. Create a Page Rule:
    • Go to the Page Rules section in your Cloudflare dashboard.
    • Add a new rule with the URL pattern www.example.com/*.
    • Set the action to Forwarding URL with a 301 redirect to https://example.com/$1.

This setup ensures that all traffic to the www subdomain is redirected to the non-www version.

Tips and Tricks for Using Nginx Proxy Manager

  1. Using Access Control:

    • You can restrict access to certain services based on IP addresses. Navigate to Access Lists to create rules that allow or deny specific IPs.
  2. Setting Up Authentication:

    • You can secure certain proxy hosts with Basic Auth under the Access tab when adding or editing a proxy host.
  3. Using Websockets:

    • If you need to proxy WebSocket connections, Nginx Proxy Manager handles it automatically, but ensure your backend supports WebSockets.
  4. Custom Nginx Configurations:

    • Use the Advanced tab to add custom configurations, such as increasing buffer sizes for large requests:
      proxy_buffers 16 16k;
      proxy_buffer_size 32k;
      
  5. Monitoring and Logging:

    • Nginx Proxy Manager provides logs for each proxy host. This can be invaluable for debugging issues with service accessibility or performance.
  6. Multi-Domain Management:

    • NPM supports multiple domains, allowing you to manage all your sites from a single interface.
  7. Regular Backups:

    • Regularly back up your configuration files and SSL certificates to prevent data loss.
  8. Updating Nginx Proxy Manager:

    • To keep your installation up to date, pull the latest image and recreate your containers:
      docker-compose pull
      docker-compose up -d
      

Conclusion

Nginx Proxy Manager is an invaluable tool for simplifying the management of Nginx reverse proxies, especially for users unfamiliar with Nginx’s configuration syntax. With features like SSL management, redirections, and access control, NPM provides a robust solution for web application deployment.

By following the setup guide and tips provided, you can efficiently manage your web services, ensure secure connections with SSL, and handle redirects seamlessly. Whether you’re a beginner or a seasoned professional, Nginx Proxy Manager makes it easier to focus on your applications rather than the infrastructure.

Further Reading

For more detailed information and troubleshooting tips, you can refer to the following resources: