2 min read

Step-by-Step Guide to Load Balancing with Custom Nginx Configuration in Nginx Proxy Manager

Step-by-Step Guide to Load Balancing with Custom Nginx Configuration in Nginx Proxy Manager

Load balancing is a crucial aspect of managing web traffic efficiently, ensuring high availability, and optimizing resource utilization. Nginx Proxy Manager is a powerful tool that simplifies the process of setting up and managing reverse proxies with load balancing capabilities. In this step-by-step guide, we'll walk through the process of configuring load balancing using Nginx Proxy Manager.

Prerequisites:

  1. Nginx Proxy Manager installed and running.
  2. Access to the Nginx Proxy Manager web interface.
  3. Knowledge of the IP addresses and ports of your backend servers.

Step 1: Access Nginx Proxy Manager Web Interface

Open your web browser and navigate to the Nginx Proxy Manager web interface. Typically, it's accessible at http://your-server-ip:81. Log in using your credentials.

Step 2: Create Custom Configuration Snippet

  • Connect to your server where Nginx Proxy Manager is installed.
  • Navigate to the location where you have mounted the Nginx configuration files. In this case, it's /data/nginx/custom/.
cd /data/nginx/custom
  • Create a new file named http_top.conf:
touch http_top.conf
  • Edit the file using a text editor (e.g., nano or vim):
nano http_top.conf
  • Add the following upstream block to the file, specifying the IP addresses and ports of your backend servers:
upstream backend {
    server 192.168.0.69:8080;
    server 192.168.0.100:8090 backup;
}

Save the changes and exit the text editor.

Step 3: Add Custom Configuration in Nginx Proxy Manager

  • In the Nginx Proxy Manager dashboard, click on the "Proxy Hosts" tab in the left sidebar.
  • Click the "Add Proxy Host" button to create a new reverse proxy configuration.
  • Fill in the necessary details in the basic configuration (Domain Names, Forward Hostname/IP, Forward Port, etc.).
  • Navigate to the "Advanced" tab.
  • In the "Custom Nginx Configuration" section, add the following
location / {
    proxy_pass http://backend;
}
  • Save the proxy host configuration.

Step 4: Test and Verify

  1. After saving the configuration, test the load balancing setup by accessing your domain or subdomain in a web browser.
  2. Monitor the Nginx Proxy Manager dashboard and the access logs to ensure that requests are being distributed among the backend servers.

For more information on HTTP Load Balancing in NGINX click here.

Congratulations! You have successfully set up load balancing using custom Nginx configuration snippets in Nginx Proxy Manager. Adjust the configuration as needed and scale your infrastructure to handle increased traffic efficiently.