我正在尝试将 Varnish 添加到我现有的开发环境中,该环境使用 Valet for windows。我安装了 docker desktop 并使用 this tutorial 使用 Varnish 设置了一个容器。我将容器上的 80 端口暴露为主机上的 80 端口。
当我查看 Windows 资源监视器时,我看到
com.docker.backend.exe
(Varnish) 在端口 80 上侦听。我还看到 nginx 在端口 8080 和 443 上正确侦听。
我的 nginx/varnish conf 看起来像这样:
server {
listen 8080;
server_name magento.test www.magento.test *.magento.test;
return 302 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name magento.test www.magento.test *.magento.test;
root /;
charset utf-8;
client_max_body_size 512M;
http2_push_preload on;
ssl_certificate "C:/Users/tfish/.config/valet/Certificates/magento.test.crt";
ssl_certificate_key "C:/Users/tfish/.config/valet/Certificates/magento.test.key";
location / {
proxy_pass http://127.0.0.1:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
rewrite ^ "C:/Users/tfish/AppData/Roaming/Composer/vendor/cretueusebiu/valet-windows/server.php" last;
}
}
backend default {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 600s;
.probe = {
.url = "/health_check.php";
.timeout = 2s;
.interval = 5s;
.window = 10;
.threshold = 5;
}
}
当我访问
http://magento.test
时,我立即得到 503 后端获取失败。当我访问 https://magento.test
时,网站加载正确,但我看不到 Varnish 响应标头。
当我得到 503 backend fetch failed 时,varnishlog 错误是:
-- FetchError backend default: fail errno 111 (Connection refused)
更新:
我注意到我无法从我的 docker 容器内部卷曲
http://localhost:8080
:curl: (7) Failed to connect to localhost port 8080: Connection refused
根据这篇文章将后端 VCL 配置从
127.0.0.1
更新为 host.docker.internal
有效。该网站现在加载。
但是,我仍然没有得到任何 Varnish 标头。