【发布时间】:2018-11-16 17:10:19
【问题描述】:
我想尝试一个 Varnish 配置,它在默认端口 6081 上进行侦听,而 Apache 保持在 80 上。这个想法来自 blog about varnish。
iptables 重定向然后将所有 80 流量发送到 6081。这样做使我能够继续使用我的 Web 控制面板而不会破坏它(该面板在 8080 本身上运行,并且在 Apache 的侦听更改时也会中断)。
现在我正在对服务器进行全新安装,只安装了 Apache 和 Varnish,只是想看看它是否可以正常工作。我可以让 Varnish 启动并运行:
curl -I 192.168.0.1:6081
但是,即使 iptable 规则已启动并正在运行,它也不能单独在 IP 上工作。以下是我显然使用虚拟 ip 192.168.0.1 的结果和设置
iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 6081
IP 表规则 --(来自here)
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-port 6081
curl -I 使用端口 6081 的结果
curl -I http://192.168.0.1:6081
HTTP/1.1 200 OK
Date: Wed, 06 Jun 2018 21:45:20 GMT
Server: Apache/2.4.25 (Debian)
Last-Modified: Wed, 06 Jun 2018 21:08:27 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 2
Age: 0
Via: 1.1 varnish (Varnish/6.0)
ETag: W/"29cd-56dff9168052e-gzip"
Accept-Ranges: bytes
Connection: keep-alive
curl -I 没有端口的结果
curl -I http://192.168.0.1
HTTP/1.1 200 OK
Date: Wed, 06 Jun 2018 21:36:49 GMT
Server: Apache/2.4.25 (Debian)
Last-Modified: Wed, 06 Jun 2018 21:08:27 GMT
ETag: "29cd-56dff9168052e"
Accept-Ranges: bytes
Content-Length: 10701
Vary: Accept-Encoding
Content-Type: text/html
/etc/default/varnish
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m
/etc/varnish/default.vcl
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "80";
我错过了什么? Apache 在 80,Varnish 在 6081,80 流量被重定向到 Varnish 正在监听的 6081。
【问题讨论】:
标签: varnish varnish-vcl