Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an AWS ELB behind Varnish - is it possible?

I'm trying to put a set of EC2 instances behind a couple of Varnish servers. Our Varnish configuration very seldom changes (once or twice a year) but we are always adding/removing/replacing web backends for all kinds of reasons (updates, problems, load spikes). This creates problems because we always have to update our Varnish configuration, which has led to mistakes and heartbreak.

What I would like to do is manage the set of backend servers simply by adding or removing them from an Elastic Load Balancer. I've tried specifying the ELB endpoint as a backend, but I get this error:

Message from VCC-compiler:
Backend host "XXXXXXXXXXX-123456789.us-east-1.elb.amazonaws.com": resolves to multiple IPv4 addresses.
Only one address is allowed.
Please specify which exact address you want to use, we found these:
123.123.123.1
63.123.23.2
31.13.67.3
('input' Line 2 Pos 17)
.host = "XXXXXXXXXXX-123456789.us-east-1.elb.amazonaws.com";

The only consistent public interface ELB provides is its DNS name. The set of IP addresses this DNS name resolves to changes over time and with load.

In this case I would rather NOT specify one exact address - I would like to round-robin between whatever comes back from the DNS. Is this possible? Or could someone suggest another solution that would accomplish the same thing?

Thanks, Sam

like image 211
user1950119 Avatar asked Jan 05 '13 01:01

user1950119


People also ask

What happens if AWS ELB goes down?

If an individual ELB instance were to fail, it would be replaced automatically, much in the way autoscaling replaces failed instances. You can usually tell how many instances are in your ELB by doing a DNS lookup - you will see multiple IP addresses returned.

What is varnish AWS?

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as APIs. In contrast to other web accelerators, such as Squid, which began life as a client-side cache, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator.

What is Internet facing ELB?

An internet-facing load balancer has a publicly resolvable DNS name, so it can route requests from clients over the internet to the EC2 instances that are registered with the load balancer. If a load balancer is in a VPC with ClassicLink enabled, its instances can be linked EC2-Classic instances.

Which ELB feature is used to allow existing connections to close cleanly?

One of your EC2 instances that is behind an Elastic Load Balancer (ELB) is in the process of being de-registered. Which ELB feature can be used to allow existing connections to close cleanly? Options are : Deletion Protection.


2 Answers

You could use a NGINX web server to deal with the CNAME resolution problem:

User-> Varnish -> NGNIX -> ELB -> EC2 Instances
        (Cache Section)        (Application Section)

You have a configuration example in this post: http://blog.domenech.org/2013/09/using-varnish-proxy-cache-with-amazon-web-services-elastic-load-balancer-elb.html

Juan

like image 123
Juan Domenech Avatar answered Sep 21 '22 03:09

Juan Domenech


I wouldn't recommend putting an ELB behind Varnish.

The problem lies on the fact that Varnish is resolving the name assigned to the ELB, and it’s caching the IP addresses until the VCL get’s reloaded. Because of the dynamic nature of the ELB, the IPs linked to the cname can change at any time, resulting in Varnish routing traffic to an IP which is not linked to the correct ELB anymore.

This is an interesting article you might like to read.

like image 43
Abs Avatar answered Sep 24 '22 03:09

Abs