-->

清漆不处理ESI包括(Varnish not processing ESI includes)

2019-09-16 10:51发布

我试图建立光油处理ESI包括在当地的环境。

我在虚拟机中运行清漆和内容在主机上运行。

我有两个文件“的index.html”和“test.html文件”。 这些都存储在一个Apache服务器的文档根目录称为“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中的标记示出,它不被处理。

我检查了光油日志,但里面还有相关的ESI没有错误并没有什么。

任何人都可以看到我在做什么错在这里? 让我知道,如果需要更多的信息.​​.谢谢

Answer 1:

如果您的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 /在URL到远程服务器的流量。

sub vcl_recv {
      if (req.url ~ "^/esi/") {
            set req.backend = hostmachine;
            set req.http.host = "www.correctdomainname.com";
      } else {
            set req.backend = default;
      }
}

我工作的同样的事情,现在所以给它一个尝试,让我知道它是否适合你。



Answer 2:

光油只执行ESI的一小部分。 由于2.1 3 ESI语句:

    esi:include
    esi:remove
    <!--esi ...-->

基于变量和饼干内容替代不落实,但在路线图上。 光油不会处理在HTML注释ESI指令。 对于ESI工作,你需要激活ESI处理VCL,就像这样:

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            */
}

}



Answer 3:

对于ESI工作(清漆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


Answer 4:

确保你的配置是由漆读取。 如果您在泊坞窗容器中运行清漆你可能必须重建它。

您可以将您的配置更改为可笑,看看它是否抓住了它。 例如改变后端W3.org网站。

如果这仍然给你同样的结果,不使用你的配置。



文章来源: Varnish not processing ESI includes