2

Is possible with Varnish configure multiple backends for one site? For example I have high avalibility site with multiple backends.

For example I have site www.goodies.com which is running on php 5.6. So I have 3 www-nodes as backend www-node5.6a www-node5.6b www-node5.6c

I have configured backends in Varnish like this:

backend www-node5.6a { .host = "10.0.0.11"; .port = "80"; .connect_timeout = 6000s; .first_byte_timeout = 6000s; .between_bytes_timeout = 6000s; } backend www-node5.6b { .host = "10.0.0.12"; .port = "80"; .connect_timeout = 6000s; .first_byte_timeout = 6000s; .between_bytes_timeout = 6000s; } backend www-node5.6c { .host = "10.0.0.13"; .port = "80"; .connect_timeout = 6000s; .first_byte_timeout = 6000s; .between_bytes_timeout = 6000s; } 

my question is, how to configure Varnish so user will be randomly use to any of this backends for this specific one site?

2
  • Googling for "varnish load balancing" serves up plenty of examples. BTW, 6000 seconds timeout for connect?! And the rest... Commented Mar 27, 2019 at 15:08
  • Actually no, just wanted to make it more simple. There is the only reason so if there will be high traffic so the www-node will not crash. Commented Mar 27, 2019 at 15:08

1 Answer 1

4

What you are looking for if you want random distribution of the content you need something like this in your config file:

director cl1 random { { .backend = [Backend0]; .weight = 1; } { .backend = [Backend1]; .weight = 1; } } 

More information about how Varnish backends work can be found here. I found the above snippet from this blog. You can also do this on the basis of url, as seen here. You can also read more on configuring Varnish for High Availability here.

You should consider doing health checks and setting up and defining an actual director in round robin mode. Random is random. In theory, every single user that visits your site could be randomly sent to the same backend and that would be just as "random" as splitting things evenly based on backend health and status. Looking to another source they have something along these lines:

import directors; backend [Backend0] { .host = "192.168.0.10"; .probe = { .url = "/"; .timeout = 1s; .interval = 5s; .window = 5; .threshold = 3; } } backend [Backend1] { .host = "192.168.0.10"; .probe = { .url = "/"; .timeout = 1s; .interval = 5s; .window = 5; .threshold = 3; } } sub vcl_init { new vdir = directors.round_robin(); vdir.add_backend([Backend0]); vdir.add_backend([Backend1]); } 

Make the changes as necessary for what makes sense in your environment. Please read over all the links and documentation as well as make a backup of your old configuration before trying any of this.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.