Tutorials > How to configure Load Balancing with NGINX on Jelastic Cloud

How to configure Load Balancing with NGINX on Jelastic Cloud

Published on: 17 February 2020

Cache Jelastic Cloud NGINX

Load Balancing is a process of distributing load across multiple components. This process is performed by a specific type of nodes called ‘load balancers’. In Jelastic Cloud, load balancers can be added manually to the virtual environment.

Jelastic Cloud supports different types of load balancers:
  • NGINX: one of the most famous open source servers in the world that ensures high performance and application efficiency. It provides an affordable and highly available platform for hosting applications, due to its scalability, security and high efficiency in the use of resources.

  • HAProxy: a fast and reliable open source solution that handles very large amounts of traffic and offers high availability, load balancing and proxies for TCP and HTTP based applications.

  • Varnish: a web application accelerator, also known as HTTP reverse proxy, with caching for dynamic websites with high traffic. Unlike other proxy servers, it was initially designed to be focused exclusively on the HTTP protocol. However, within Jelastic, it is bundled with the NGINX server (run as an HTTPS proxy).

  • Apache is an open source solution, which offers high customization options through its modular structure. Apache balancing can be configured to meet the unambiguous requirements of each given environment, while, at the same time, ensuring benefits such as security, high availability, speed, reliability and authentication.

  • LiteSpeed ​​Web ADC is a commercial high-performance HTTP load balancing solution that offers advanced security, enterprise-level performance and many other features.
For production purposes, the use of multiple calculation nodes with a load balancer is the preferable approach, as it ensures redundancy and high availability of the system.

TCP Load balancing with NGINX

Jelastic Cloud clients can use a TCP load balancer to balance requests across databases, mail servers and other network services. By using the TCP protocol instead of the HTTP one faster balancing is achieved.

The load balancer receives a connection request from a client application via a network socket. This component decides which node in the environment has to receive the request. For this distribution request, Jelastic uses a Round Robin algorithm.

To use TCP load balancing, create a Jelastic Cloud environment with at least one application server:

Jelastic environment creation

N.B. Remember to enable public IP for your NGINX instance.

Then, click on the "Config" button to configure your NGINX instance:

NGINX instance configuration

In the newly opened tab, open the "tcpmaps" folder and then edit the "mappings.xml" file to specify the ports for the backend and frontend. Then, save all the changes:

Port Mappings NGINX

Restart the NGINX instance to apply all the changes:

Restart the NGINX instance

NGINX load balancer cache

The NGINX load balancer allows you to store files in a temporary memory to reduce the number of requests to the web server. When a user tries to view a resource he has recently viewed, the browser will retrieve it from the NGINX cache, instead of from the web server.

To enable the cache, click on the "Config" button of the previously created NGINX instance:

NGINX instance configuration

Edit the cache.conf file and uncomment the existing configuration lines, as shown in the following image:

NGINX cache settings

Save your changes and restart your instance.

Restart the NGINX instance

At this point, you will have enabled caching.