Skip to content

Feature/add load balancing#5727

Open
jakubstrama wants to merge 3 commits into
NginxProxyManager:developfrom
jakubstrama:feature/add-load-balancing
Open

Feature/add load balancing#5727
jakubstrama wants to merge 3 commits into
NginxProxyManager:developfrom
jakubstrama:feature/add-load-balancing

Conversation

@jakubstrama

Copy link
Copy Markdown

Why

Nginx supports upstream load balancing via upstream {} blocks, allowing a proxy host to distribute traffic across multiple backend servers. Currently, NPM only supports a single forward_host:forward_port target per proxy host, with no way to configure multiple servers or a balancing strategy.

This PR adds full Nginx upstream load balancing support to proxy hosts.

Balancing methods (mapped to Nginx directives)

  • Round Robin — default, no directive needed
  • Least Connectionsleast_conn;
  • IP Hash (sticky sessions)ip_hash;

Per-server parameters

  • weight — relative request weight for round-robin distribution
  • max_fails / fail_timeout — passive health check thresholds
  • backup — receive requests only when all primary servers are down
  • down — permanently mark a server unavailable (graceful removal)

The Nginx template generates an upstream npm-<id> {} block at the top of each proxy host configuration file (valid at the http context level) and switches proxy_pass to target the upstream group when upstream servers are configured.

Existing single-target proxy hosts remain unaffected.

API changes

Two new optional fields are accepted when creating or updating a proxy host:

  • lb_method (enum)
  • upstream_servers (array of objects)

Both default to an empty configuration using Round Robin, so existing integrations require no changes.

Constraint enforcement

Nginx does not allow the backup flag to be used together with ip_hash. This constraint is enforced in both the backend and frontend:

  • Backend: returns 400 Bad Request before attempting to update the Nginx configuration.
  • Frontend: the Backup option is automatically disabled and cleared when IP Hash is selected.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • API changes
  • Performance improvement
  • Test addition or update

AI Usage

  • AI was used to write this.
  • AI was used to review this.

@nginxproxymanagerci

Copy link
Copy Markdown

Docker Image for build 2 is available on DockerHub:

nginxproxymanager/nginx-proxy-manager-dev:pr-5727

Note

Ensure you backup your NPM instance before testing this image! Especially if there are database changes.
This is a different docker image namespace than the official image.

Warning

Changes and additions to DNS Providers require verification by at least 2 members of the community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant