2 NGINX Load Balancer Services

This topic describes about the installation and configuration of the NGINX load balancer services.

2.1 Installation and Setup

This topic describes about the installation and setup.

2.1.1 Download

This topic provides systematic instructions to download the tar file.

  1. Download the tar file from nginx.org/download/ Index list.
  2. Extract the tar file using tar -xvf command.

2.1.2 Install

This topic provides systematic instructions to install the tar file.

  1. Choose the installation location using --prefix=path parameter.
  2. Find the ./configure file in the extracted folder above.
  3. Inside the extracted folder, run the following commands one after other
    ./configure --prefix=/scratch/nginx --with-http_ssl_module
    make
    The nginx is installed at /scratch/nginx.

2.1.3 Start and Stop Procedure

This topic provides systematic instructions to start and stop procedure of files.

  1. Find the sbin folder inside the installed directory.
  2. Run ./nginx file inside sbin folder to start nginx.
  3. Write ./nginx -s stop command to stop nginx.

2.1.4 Configuration

This topic provides systematic instructions to configure the server.

The configuration is done in the nginx.conf file inside the conf directory.

  1. Create, upstream, and place the URLs to be routed for Load Balancing.
    upstream config{
         server 10.184.155.115:7004;
         server 10.184.155.115:7004;
         }
    
    upstream gateway{
         server 10.184.155.115:7005;

    Note:

    There are two load balancers defined. Default load balancing technique is Round Robin. This block must be placed inside the http block.
  2. Configure the Server block.
    It is also placed inside the http block. The server block is used for routing purposes. The block is as shown below.
    server {
         listen 8090;
         server_name _;
    
         location / {
              proxy_pass http://config;
         }
         location /api {
              rewrite /api/(.*) /$1 break;
              proxy_pass http://gateway;
         }
    
         error_page 500 502 503 504 /50x.html;
    • The 8090 acts as the listen port for nginx.
    • The server_name property must be given if the requests are from a particular server. The Server accepts requests from any server.
    • The proxy_pass is used to route the request and the request format is defined in the location tag.
    • The rewrite tag is used to manipulate the requests.

    Note:

    Make sure the firewall is open for other IPs to pass the request.

2.2 Load Balancer Route Configurations

This topic describes about load balancer route configurations.

The below configurations gives the route configurations for the load balancer.

Note:

The underlying syntax and semantics may vary from the load balancer to load balancer.
   upstream config-service{
      server << IP Or Hostname of the PLATO Configuration
Service 1 >>:<< Port of the PLATO Configuration Service 1 >>;
      server << IP Or Hostname of the PLATO Configuration
Service 2 >>:<< Port of the PLATO Configuration Service 2 >>;
      server << IP Or Hostname of the PLATO Configuration
Service 3 >>:<< Port of the PLATO Configuration Service 3 >>;
      server << IP Or Hostname of the PLATO Configuration
Service N >>:<< Port of the PLATO Configuration Service N >>;
   }
   upstream api-gateway{
      server << IP Or Hostname of the PLATO API Gateway Service
1 >>:<<Port of the PLATO API Gateway Service 1 >>;
      server << IP Or Hostname of the PLATO API Gateway Service
2 >>:<<Port of the PLATO API Gateway Service 2 >>;
      server << IP Or Hostname of the PLATO API Gateway Service
3 >>:<<Port of the PLATO API Gateway Service 3 >>;
   }
   upstream <<Context Root of the PLATO UI APP Shell>> {
      server << IP Or Hostname of the PLATO UI APP Shell 1 >>:<<
Port of the PLATO Configuration Service 1 >>;
      server << IP Or Hostname of the PLATO UI APP Shell 2 >>:<<
Port of the PLATO UI APP Shell 2 >>;
      server << IP Or Hostname of the PLATO UI APP Shell 3 >>:<<
Port of the PLATO UI APP Shell 3 >>;
              server << IP Or Hostname of the PLATO UI APP Shell N >>:<<
Port of the PLATO UI APP Shell N >>;
    }
    server {
      listen << PORT OF THE LOAD BALANCER >>;
          server_name _;
          location /config-service {
              proxy_pass http://config-service;
          }
          location /api-gateway {
              proxy_pass http://api-gateway;
          }