/
Setup for reverse proxy

Setup for reverse proxy

Proxying Traffic to a Group of Servers

info

Use a reverse proxy to route inbound traffic to particular internal servers


Follow the steps below

  1. Setup an upstream block within the http block
  2. nginx configuration

    http
    {
        upstream my_glassfish_cluster 
        {
            server backend1.example.com weight=5;
            server 192.168.99.100:28080;
            server 192.168.99.100:28081 backup;
        }
    }

    Use weight to specify importance (1:lowest - 5:highest), use backup to specify only route to this server if all other servers in the cluster fail

  3. Now specify the upstream group that nginx will pass requests to (can be any one of the following protocols: proxy_pass, fastcgi_pass, memcached_pass, uwsgi_pass, or scgi_pass)

  4. nginx configuration

    http
    {
       ...
       server 
       {
          location / 
          {
             proxy_pass http://my_glassfish_cluster;
          }
       }
    }

    This will pass all http requests up to my_glassfish_cluster server group

Choosing a Load Balancing Method

NGINX supports four load balancing methods in the open source version and one extra method in the paid version

Open source methods

  • round-robin (default) - iterate equally around each server in a server group
  • least_conn - send requests to server with the least number of connections
  • ip_hash - using a hash algorithm, select server in a server group based on client's IP address
  • hash -  the server to which a request is sent is determined from a user-defined key which may be a text, variable, or their combination

Paid version

  • All of above
  • least_time - for each request, NGINX Plus selects the server with the lowest average latency and the least number of active connections, where the lowest average latency is calculated based on which of the following parameters is included on the least_timedirective:
    • header – Time to receive the first byte from the server
    • last_byte – Time to receive the full response from the server

The load balancer

NGINX  has been used as the load balancer, it must be running so that you can access either of the running tomcat servers.  To check its status run the command 

tasklist /fi "imagename eq nginx.exe".  If it is running you will see the following output

Image Name                PID      Session Name     Session#    Mem Usage
========================= ======== ================ =========== ============
nginx.exe 5432 Console 2 5,748 K
nginx.exe 3388 Console 2 5,984 K

Starting, stopping and reloading load balancer

Starting NGINX, run the command

  • start  nginx.exe

Stopping NGINX, run the command

  • nginx -s quit

Reloading nginx.conf if changed whilst nginx is running

  • nginx -s reload