如何设置Varnish与Apache和Tomcat一起工作



我有一个Ubuntu 12.0服务器在端口80上运行Varnish 4,在8080上运行Apache 2.4。我安装了运行在端口8181上的Tomcat 7,它只运行一个Liferay站点。我也想配置Varnish与Tomcat一起工作。我该如何设置呢?我当前的设置是:

/etc/default/varnish
DAEMON_OPTS="-a :80 
         -T localhost:6082 
         -f /etc/varnish/default.vcl 
         -S /etc/varnish/secret 
         -s malloc,256m"

/etc/varnish/default.vcl
backend default {
   .host = "123.456.789.000";
   .port = "8080";
   .connect_timeout = 580s;
   .first_byte_timeout = 580s;
   .between_bytes_timeout = 580s;
}

如果我将浏览器指向123.456.789.000:8181,则Tomcat站点可以工作。我将用我的DNS设置注册器以响应"www.mytomcatsite.com",但我如何避免URL上的":8181"?

使用Apache一切正常

TIA。

来自清漆文档:

我们添加一个新的后端:

backend java {
    .host = "127.0.0.1";
    .port = "8000";
}

现在我们需要告诉Varnish将差异URL发送到哪里。让我们看看vcl_recv.:

sub vcl_recv {
    if (req.url ~ "^/java/") {
        set req.backend_hint = java;
    } else {
        set req.backend_hint = default;
    }
}

如果你想在虚拟主机的基础上完成这个路由,你只需要检查req.http.host:

sub vcl_recv {
    if (req.http.host ~ "foo.com") {
        set req.backend_hint = foo;
    } elsif (req.http.host ~ "bar.com") {
        set req.backend_hint = bar;
    }
}

:

  • https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html多个后台
  • https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html backends-and-virtual-hosts-in-varnish

注意:这是为清漆4。VCL语法在Varnish 3中将略有不同。

最新更新