如何从清漆3中排除虚拟主机?

时间:2014-05-12 22:01:37

标签: apache virtualhost varnish varnish-vcl

我想从varnish 3 config

中排除单个虚拟主机

缓存: [www] .domain.tld

不要缓存: host.domain.tld

### default.vcl
backend foo { .host = "domain.tld"; .port = "8880"; }
backend bar { .host = "host.domain.tld"; .port = "8880";}
# ...
if (req.url == "host.domain.tld") { set req.backend = bar; } 
if (req.url == "host.domain.tld") { return(pass); }
if (req.http.Cookie && req.url == "host.domain.tld") { return(pass); }

# ...

### httpd.conf
Listen 8880
<VirtualHost vhost.domain.tld:8880>
    DocumentRoot /var/www/foo/
    ServerName vhost.doman.tld
</VirtualHost>

请求永远不会到达虚拟主机。我想问题是我在端口80上请求并且主机侦听端口8880.
我能做些什么来修复这个?

1 个答案:

答案 0 :(得分:1)

req.url不包含域名。你需要这样的东西:

sub vcl_recv {
  if (req.http.host == "host.domain.tld") {
    set req.backend = bar;
    return (pass);
  }
}

这会将进入域“host.domain.tld”的任何请求的后端设置为“bar”并直接传递给后端(绕过缓存)。