Realizing vhosts with varnish

Stefan Pommerening pom at dmsp.de
Thu Dec 16 10:38:26 CET 2010


Please use double equation marks:

if (req.http.Host == "domain1.com") { ..... }

Stefan


Am 16.12.2010 10:06, schrieb Frank Helmschrott:
> Hi list,
>
> here's my situation:
>
> I got one dedicated server to run varnish and multiple backend servers
> delivering websites. These Backend servers host several different web
> projects and the standard solution is the each project runs without
> any cache or anything else.
>
> Now i want to take some load off of the servers by using varnish and
> routing them through the cache. I thought about different solutions
> and searched around a bit and came across this blog post
> (http://www.varnish-software.com/blog/virtual-hosts-varnish) and also
> found the mailing list entry on that topic. I tried it out in my
> config but it didn't work. I think this is due to my missing knowledge
> so i thought i'd ask here.
>
> I currently have a default.vcl containing these lines:
>
> sub vcl_recv {
>          if (!req.http.Host)
>          {
>                  error 404 "Need a host header";
>          }
>
>          set req.http.Host = regsub(req.http.Host, "^www\.", "");
>          set req.http.Host = regsub(req.http.Host, ":80$", "");
>
>          if (req.http.Host = "domain1.com")
>          {
>                  include "/etc/varnish/vhost-domain1.com.vcl";
>          }
>          elsif (req.http.Host = "domain2.com")
>          {
>          include "/etc/varnish/vhost-domain2.com.vcl";
>          }
> }
>
>
> The two vhost files contain a basically working configuration (it
> workes well when using it as the only config). With the default.vcl
> from above varnish doesn't start. Unfortunately on my server (using
> CentOS 5.5 and varnish from EPL) i don't get any error messages what
> may be wrong. Is there something missing that must be set before this
> if/else statement can be handled?
>
> I'm currently a bit confused and don't know where to continue. Any
> help is appreciated. I'm using the latest Version from EPEL which is
> 2.0.6
>
> One additional question: When fetching the files from backend servers,
> doesn't varnish send a hostname? I tried putting some more vhosts on
> one IP on the backend and setup this IP in varnish as backend server
> but what varnish delivered was the default content from the backend
> instead of the vhosts content the hostname belonged to.
>
> Thanks for helping!


-- 

*Dipl.-Inform. Stefan Pommerening
Informatik-Büro: IT-Dienste & Projekte, Consulting & Coaching*
An der Kappe 171 B, 13583 Berlin, Germany, Email: pom at dmsp.de 
<mailto:pom at dmsp.de>
Telephone(Office): +49-(0)30 / 375 84 888, Mobile: +49 - (0)179 / 394 80 72
Fax(Office): +49-(0)30 / 604 8594, http://www.dmsp.de <http://www.dmsp.de/>

Der Inhalt dieser E-Mail ist vertraulich und ausschließlich für den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene
Adressat dieser E-Mail oder dessen Vertreter sein sollten, so beachten
Sie bitte, dass jede Form der Kenntnisnahme, Veröffentlichung,
Vervielfältigung oder Weitergabe des Inhalts dieser E-Mail unzulässig
ist. Wir bitten Sie, sich in diesem Fall mit dem Absender der E-Mail in
Verbindung zu setzen.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20101216/97f36e4d/attachment-0003.html>


More information about the varnish-misc mailing list