Philipp Bundschuh
Philipp Bundschuh

Reputation: 11

varnish, apache and namebased virtual host with own ip addresses

I have a apache2-webserver with several name-based virtual hosts; each host has its own ip address, so the apache is not listening on *:80, but on 123.456.789.012:80.

Now I want to cache the websites with varnish. I found several howtos, either ip-based hosts (listening on *:80) or namebased hosts with only one ip address.

How do I have to setup my varnish to make it work with my apache2-configuration?

Upvotes: 1

Views: 1221

Answers (1)

Gauthier Delacroix
Gauthier Delacroix

Reputation: 709

You will need one backend per IP, and then send each hostname to the right backend.

Example :

backend Site1 {
    .host = "123.456.789.001";
    .port = "80";
}

backend Site2 {
    .host = "123.456.789.002";
    .port = "80";
}

sub vcl_recv {
    if (req.http.Host == "www.site1.com") {
        set req.backend Site1
    } elseif (req.http.Host == "www.site2.com") {
        set req.backend Site2
    } elseif
}

(Not sure about backend syntax since I only use directors)

Upvotes: 1

Related Questions