Configuring Nginx as a load balancer

This tutorial will walk you through configuring Nginx as a load balancer to direct client requests to a group of PowerServer Web APIs. You will have to configure Nginx as a load balancer and use the IP hash load-balancing method to support session persistence. With IP hash, the client's IP address is used as a hashing key to determine which PowerServer Web APIs should be selected for the client's request. This ensures the requests from the same user session is always directed to the same PowerServer Web APIs.


However, the hash-based session persistence cannot guarantee that user sessions are evenly distributed across servers. For example, there may be situations where a lot of user sessions are coming with the same IP address (behind proxies) and all these user sessions will go to the same server, which might cause unbalanced load.

If you are concerned with this potential impact, you can consider the following options:

  • Use the Nginx third-party module (Nginx Sticky Module) to support session persistence using cookies.

  • Use another server that supports cookie-based session persistence such as Nginx Plus (which is a commercial product), IIS, or Apache. See the corresponding sections for detailed instructions.

To configure Nginx as a load balancer and use the IP hash load-balancing method,

Step 1: Follow the sections below to install Nginx.

Step 2: Configure Nginx to direct requests to the PowerServer Web APIs group using the IP hash load-balancing method.

  1. Open the nginx.conf file in a text editor (nginx.conf is located in the ..\nginx-1.19.10\conf folder in Windows, or /etc/nginx/ in Linux).

  2. Under the "server" block that defines the virtual server, add another "server" block and "upstream" block that define the server group.

    • The "listen" directive specifies the port number for the requests. The Web API URL should point to this port number.

    • The "proxy_pass" directive forwards the request to the server group defined in the "upstream" directive, therefore, it should match with the upstream name.

    • The "upstream" directive defines the PowerServer Web APIs group.

      In the following example, the "upstream" block consists of three server configurations; it could consists of more.

      The "upstream" block also consists of the "ip_hash" directive which defines that the IP hash load-balancing method will be used when determining which server in the group the request will be directed to.

    The following configuration defines a PowerServer Web APIs group named webapi which consists of three .NET servers:,, and, and requests made to the URL: http://<server>:8080/ will be redirected to the PowerServer Web APIs group.

        server {
            listen  8080;
            location / {
               proxy_set_header Host $http_host;
               proxy_pass http://webapi;
        upstream webapi{