当apache侦听端口80时,设置清除以侦听不同的端口

时间:2015-09-04 09:47:46

标签: apache varnish

我已将设置清漆4设置为在端口8081上运行,而apache配置为在端口80上运行。 我的设置问题是当我浏览我的域名时 访问http //:mydomain.com:8180/
。 我得到(301)永久重定向到http //:mydomain.com/。 由于此重定向无法区分调用缓存域http //:mydomain.com:8180 / visa v未缓存域名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;
}

.......

responce标头显示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

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

1 个答案:

答案 0 :(得分: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不会重定向

相关问题