【问题标题】:setup varnish to listen on different port while apache listens on port 80设置 varnish 监听不同的端口,而 apache 监听端口 80
【发布时间】:2015-09-04 09:47:46
【问题描述】:

我已将 varnish 4 设置为在端口 8081 上运行,而 apache 配置为在端口 80 上运行。 我的设置的问题是当我浏览我的域时 http//:mydomain.com:8180/.
我得到一个 (301) 永久重定向到 http//:mydomain.com/。 由于此重定向,我无法区分调用缓存域 http//:mydomain.com:8180/ visa 与未缓存域 http//:mydomain.com/ 之间的区别。

我的清漆配置

DAEMON_OPTS="-a :8180\
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,1G"

.......

也是vcl

backend mydomain {
       .host = "x.x.x.x";
       .port = "80";
       .connect_timeout = 60s;
      .first_byte_timeout = 60s;
      .between_bytes_timeout = 60s;
       .max_connections = 800;
}

.......

响应头显示 apache 是重定向的。

HTTP/1.1 301 Moved Permanently
Date: Fri, 04 Sep 2015 11:58:04 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
 X-Pingback: http//:mydomain.com/xmlrpc.php
Location: http//:mydomain.com/
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=UTF-8
X-Varnish: 32795
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive

我的问题是如何停止重定向?

【问题讨论】:

    标签: apache varnish


    【解决方案1】:

    通过添加解决此问题

    set req.http.host = "http//:mydomain.com";
    

    在vlc中如下图。

    if (req.http.host ~ "mydomain.com:8180") {
                    set req.http.host = "mydomain.com";
                    set req.backend_hint = mydomain;
            }
    

    通过这样做,我们确保请求主机被 apache 识别,因此 apache 不会重定向

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 2012-05-17
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多