How to configure load balancer using Varnish in 60 seconds?

How to configure load balancer using Varnish in 60 seconds?

Varnish is an HTTP accelerator used as a load balancer or reverse proxy. It improves website performance by caching HTTP requests and responses. By distributing traffic across multiple servers, Varnish enhances performance and reliability. Additionally, it can handle static content requests, such as images and CSS files.

Kindly follow the below steps to configure the load balancer using Varnish.

Step 1. Log in to your AccuWeb.Cloud account.

Step 2. Click on NEW ENVIRONMENT to create an environment.

NEW ENVIRONMENT

Step 3. Select the Varnish Load balancer. You can select the Varnish version as per your requirements.

Configure additional settings such as app servers, state resource limits, and external IP for nodes.

Varnish Load balancer.

Step 4. Enter the Environment Name for your new environment and click on the Create button.

Your environment will be created in a few minutes.

Enter the Environment Name

The installation of Varnish is complete! The next step is to configure it.

Varnish Server Configurations

The following steps will help you adjust the Varnish load balancer to meet your needs.

Using the embedded file manager, you can edit the configuration files

Step 1. Link servers: The servers that will be used as the backends of this load balancer.

Click on the Config icon beside Load Balancer.

Config

You can add a new record to the /etc/varnish/default.vcl file, as follows:

Syntax: backend server_identifier
{ .host = "server_intenal_ip"; .port = "80";

Example

backend serv1 { .host = "10.100.2.18"; .port = "80";
.probe = { .url = "/"; .timeout = 30s;
.interval = 60s; .window = 5; .threshold = 2; } }

add a new record

Replace the following values with your own:

server_identifier -
Any preferred name of the linking server.
server_internal_ip - IP address of the required server.
Next, add another string within the sub vcl_init
section under the line new myclust = directors.hash();
as below format.
Syntax: myclust.add_backend(server_identifier, 1);

Example

myclust.add_backend(serv1, 1);

This string should contain the same server_identifier value as previously added.

After completing these configurations, save the changes and restart the load-balancer server.

Step 2. You can adjust the initial Varnish daemon’s parameters, which are read from the Varnish configuration file(/etc/varnish/varnish.params) on every balancer start-up.

Varnish configuration file

That’s All. You can follow this article to configure a Varnish load balancer.