不处理 ESI 的清漆包括 [英] Varnish not processing ESI includes
问题描述
我正在尝试设置 Varnish 以在本地环境中处理 ESI 包含.
I'm trying to setup Varnish to process ESI includes on a local environment.
我在虚拟机中运行 varnish,内容在主机上运行.
I am running varnish in a virtual machine and the content is running on the host machine.
我有两个文件index.html"和test.html".它们都存储在 apache 服务器的 docroot 中名为esi"的文件夹中.
I have two files "index.html" and "test.html". These are both stored in a folder called "esi" in the docroot of an apache server.
index.html
<h1>It Works!</h1>
<esi:include src="test.html" />
test.html
<p>ESI HAS BEEN INCLUDED</p>
Varnish 在 8000 端口的虚拟机上运行.所以我在这里访问它:http://192.168.56.101:8000/esi/
Varnish is running on the virtual machine on port 8000. So I access it here: http://192.168.56.101:8000/esi/
在虚拟机上的/etc/varnish/default.vcl 中,我将以下配置添加到文件底部:
in /etc/varnish/default.vcl on the virtual machine I have added the followin config to the bottom of the file:
sub vcl_fetch {
set beresp.do_esi = true; /* Do ESI processing */
set beresp.ttl = 24 h; /* Sets the TTL on the HTML above */
}
认为它应该处理所有请求的 ESI(不要在意它是否只是试图让这个东西工作的坏习惯:))
With the idea that it should process ESI on ALL requests (Dont care if its bad practice just trying to get this thing to work :))
加载 http://192.168.56.101:8000/esi/ 时的结果是:
<h1>It Works!</h1>
<esi:include src="test.html" />
即.ESI 显示在标记中,它没有被处理.
ie. the ESI is shown in the markup, it is not being processed.
我检查了 Varnish 日志,但是那里没有错误,也没有与 ESI 相关的内容.
I have checked the Varnish log, however there are no errors in there and nothing related to ESIs.
谁能看到我在这里做错了什么?如果需要更多信息,请告诉我..谢谢
Can anyone see what I am doing wrong here? Let me know if more information is needed.. thanks
推荐答案
如果您的 esi 包含 src 是test.html",那么 varnish 会将该请求发送到您的默认后端,即 127.0.0.1.我相信您需要为远程服务器配置第二个后端.像这样:
If your esi include src is "test.html" then varnish will be sending that request to your default backend, which is 127.0.0.1. I believe you need to configure a second backend for your remote server. Something like this:
backend default {
.host = "127.0.0.1";
.port = "8000";
}
backend hostmachine {
.host = "50.18.104.129"; # Enter your IP address here
.port = "80";
}
然后在您的子 vcl_recv 中,您需要将 URL 中包含/esi/的流量重定向到远程服务器.
Then in your sub vcl_recv you need to redirect traffic that has /esi/ in the URL to the remote server.
sub vcl_recv {
if (req.url ~ "^/esi/") {
set req.backend = hostmachine;
set req.http.host = "www.correctdomainname.com";
} else {
set req.backend = default;
}
}
我现在正在做同样的事情,所以试一试,让我知道它是否适合你.
I'm working on the same thing right now so give it a try and let me know if it works for you.
这篇关于不处理 ESI 的清漆包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!