清漆3和多个IP(虚拟主机)对我来说效果不佳

时间:2012-08-31 05:19:52

标签: apache varnish vhosts varnish-vcl

如果这看起来相当愚蠢的话,请提前告知Varnish新手如此道歉。

这是情况。我有一台有5个IP的服务器。使用ISPconfig进行大多数任务,但这可能无关紧要。

我在多个IP上配置了多个apache虚拟主机。

问题是varnish在任何非默认虚拟主机(即在vhosts中定义了静态IP的主机)上发出503,获取错误,没有后端连接(根据varnishlog)。任何*:8080 vhosts正常工作。所以我在某处遗漏了一些东西。尽管路径看起来正确,但所有vhost错误日志显示文件都不存在错误。

建议非常感谢。

我当然手动编辑了所有vhost条目并相应地进行了配置,即

<VirtualHost 00.11.22.33:8080>
      DocumentRoot /var/www/shop.example1.com/web

这是我的vcl配置

    backend default {

        .host = "127.0.0.1";
        .port = "8080";
    }

    backend example1 {
          .host = "00.11.22.33";
          .port = "8080";
    }

    backend example2 {
         .host = "11.22.33.44";
          .port = "8080";
    }


    acl purge {
            "localhost";
    }

    sub vcl_recv {

    if (req.http.host ~ "(?i)^(www.)?example1.com")

    {

        set req.http.host = "www.example1.com";
        set req.backend = example1;

    }

    if (req.http.Host ~ "shop\.example2\.com") 
    {

            set req.http.Host = "shop.example2.com";
            set req.backend = example2;


            }
        set req.grace = 2m;

  set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
  set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");




if (req.url ~ "/wp-(login|admin|cron)") {
        return (pass);
}


set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", "");

set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", "");

set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", "");

if (req.url ~ "wp-content/themes/" && req.url ~ "\.(css|js|png|gif|jp(e)?g)") {

.......
'

1 个答案:

答案 0 :(得分:1)

当然该死的很明显。

port.conf:

    NameVirtualHost *:8080
Listen 127.0.0.1:8080

它需要的是:

NameVirtualHost *:8080
Listen 127.0.0.1:8080
Listen my_IP1:8080
Listen my_IP2:8080