我正在尝试在本地环境中设置Varnish来处理ESI包含。
我在虚拟机中运行清漆,内容在主机上运行。
我有两个文件"index.html“和"test.html”。它们都存储在apache服务器docroot中的一个名为"esi“的文件夹中。
index.html
<h1>It Works!</h1>
<esi:include src="test.html" /> test.html
<p>ESI HAS BEEN INCLUDED</p>清漆在端口8000上的虚拟机上运行。所以我在这里访问它:http://192.168.56.101:8000/esi/
在虚拟机上的/etc/varnish/default.vcl中,我将下面的配置添加到文件的底部:
sub vcl_fetch {
set beresp.do_esi = true; /* Do ESI processing */
set beresp.ttl = 24 h; /* Sets the TTL on the HTML above */
}它应该对所有请求进行ESI处理的想法(不要在意它的不良实践是否只是为了让这个东西正常工作:)
加载http://192.168.56.101:8000/esi/的结果是:
<h1>It Works!</h1>
<esi:include src="test.html" />即。ESI显示在标记中,它没有被处理。
我已经检查了清漆日志,但是里面没有错误,也没有任何与环境相关的地方。
有人能看到我做错了什么吗?如果需要更多的信息,请告诉我。谢谢
发布于 2012-05-21 19:54:56
如果您的esi包含src为"test.html“,那么清漆将将该请求发送到默认后端,即127.0.0.1。我相信您需要为您的远程服务器配置第二个后端。就像这样:
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中,您需要将包含/esi/的通信量重定向到远程服务器。
sub vcl_recv {
if (req.url ~ "^/esi/") {
set req.backend = hostmachine;
set req.http.host = "www.correctdomainname.com";
} else {
set req.backend = default;
}
}我现在正在做同样的事情,所以试一试,让我知道它是否适合你。
发布于 2014-08-21 08:49:28
对于ESI works (清漆3.x),第一个字符必须是"<“,所以只需添加HTML结构
在这里我的测试:
index.php
<html>
<head>
<title></title>
</head>
<body>
<?php
$now = new \DateTime('now');
echo "hello world from index.php ".$now->format('Y-m-d H:i:s');
?>
<br/>
<esi:include src="/date.php"/>
<br/>
<esi:remove>
ESI NOT AVAILABLE
</esi:remove>
<br/>
<!--esi
ESI AVAILABLE !!
-->
</body>
</html>date.php
<?php
$now = new \DateTime('now');
echo "hello world from date.php ".$now->format('Y-m-d H:i:s');输出:
hello world from index.php 2014-08-21 10:45:29
hello world from date.php 2014-08-21 10:46:35发布于 2014-04-25 19:26:18
清漆只实现了ESI的一小部分。截至2.1,三个ESI声明:
esi:include
esi:remove
<!--esi ...-->基于变量和cookie的内容替换没有实现,而是在路线图上。清漆不会处理HTML注释中的ESI指令。要使ESI工作,需要在VCL中激活ESI处理,如下所示:
sub vcl_fetch {
if (req.url == "/index.html") {
set beresp.do_esi = true; /* Do ESI processing */
set beresp.ttl = 24 h; /* Sets the TTL on the HTML above */
} elseif (req.url == "/test.html") {
set beresp.ttl = 1m; /* Sets a one minute TTL on */
/* the included object */
}}
https://stackoverflow.com/questions/10092146
复制相似问题