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
- Proxy Hosts: Create and manage multiple proxy hosts for routing traffic.
- SSL Certificates: Easily obtain and manage Let’s Encrypt SSL certificates.
- Redirection: Set up HTTP to HTTPS redirection and custom domain redirections.
- Access Lists: Control access to certain services based on IP addresses.
- Websocket Support: Handle WebSocket connections with ease.
- 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
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
Create a Docker Network: This is optional but recommended for better organization:
docker network create nginx-proxy
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
Start Nginx Proxy Manager: Run the following command to start the services:
docker-compose up -d
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.
- Email:
Setting Up Proxy Hosts
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.
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
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
orHTTPS
depending on your configuration. - In the Advanced tab, add the following configuration:
return 301 $scheme://example.com$request_uri;
- Save the configuration.
Ensure SSL is Configured for Both Domains:
- Make sure both the
www
andnon-www
domains have valid SSL certificates set up.
- Make sure both the
Method 2: Using Cloudflare Page Rules
If you are using Cloudflare, you can manage the redirection directly through Cloudflare’s page rules.
- 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
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.
Setting Up Authentication:
- You can secure certain proxy hosts with Basic Auth under the Access tab when adding or editing a proxy host.
Using Websockets:
- If you need to proxy WebSocket connections, Nginx Proxy Manager handles it automatically, but ensure your backend supports WebSockets.
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;
- Use the Advanced tab to add custom configurations, such as increasing buffer sizes for large requests:
Monitoring and Logging:
- Nginx Proxy Manager provides logs for each proxy host. This can be invaluable for debugging issues with service accessibility or performance.
Multi-Domain Management:
- NPM supports multiple domains, allowing you to manage all your sites from a single interface.
Regular Backups:
- Regularly back up your configuration files and SSL certificates to prevent data loss.
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
- To keep your installation up to date, pull the latest image and recreate your containers:
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: