简体   繁体   English

Varnish ESI已获认可但未包括在内

[英]Varnish ESI recognized but not included

Hey everybody. 大家好 I'm using Edge Side Includes on Varnish to cache a static HTML shell, then include some dynamic HTML and a JSON object. 我在Varnish上使用Edge Side Includes来缓存静态HTML Shell,然后包括一些动态HTML和JSON对象。

The ESI for HTML is getting included properly, but the ESI for the JSON object is not being included; 已正确包含HTML的ESI,但不包含JSON对象的ESI; Debug statements establish that Varnish sees it, but it inexplicably decides not to include the JSON ESI. 调试语句确定Varnish可以看到它,但是却莫名其妙地决定不包括JSON ESI。

Here's the loading structure: 这是加载结构:


page uncached. blank page with headers to set a cookie and esi 1
esi 1 cached. A bunch of static HTML, plus esi 2 and esi 3
esi 2 uncached. A JSON object which is different on every page load.
esi 3 uncached. Some HTML which updates with every page load.

Again, esi 1 and esi 3 work just fine, but esi 2 is not getting included. 同样, esi 1esi 3可以正常工作,但是esi 2没有包含在内。 The content at esi 2 is just this: esi 2的内容就是这样:


{session_page_history_id:24231}

I read that ESI code which doesn't look like XML causes errors, so I set the runtime parameter esi_syntax=0x7 . 我读到了看起来不像XML的ESI代码会导致错误,所以我设置了运行时参数esi_syntax = 0x7 No dice, but at least I'm getting some debug data now. 没有骰子,但是至少我现在正在获取一些调试数据。

The broken call for esi 2 looks like this: esi 2的破坏调用如下所示:


<esi:include src="http://www.domain.com/dynamic_esi/print_variables?esi__desired_var_names[]=session_page_history_id&for_esi=1"/>

And the (working) call for esi 3 looks like this: esi 3的(工作)调用如下所示:


<esi:include src="http://www.domain.com/dynamic_esi/get_service_magic_html?&for_esi=1"/>

As I mentioned, Varnish appears to recognize that I'm trying to make an ESI include, but this is the only relevant Debug message I get from varnishlog: 正如我所提到的,Varnish似乎认识到我正在尝试制作ESI包含,但这是我从varnishlog获得的唯一相关调试消息:


   25 Debug        c AddBit: 6997 <<![CDATA[

window.esi__values =

<esi:include src="http://www.domain.com/dynamic_esi/print_variables?esi__desired_var_names[]=session_page_history_id&for_esi=1"/>
;

 //]]>
 </script>
 <link rel="stylesheet" href="http://www.

The output seen by a client contains all the normal content, but with the <esi> tag left intact. 客户端看到的输出包含所有正常内容,但<esi>标记保持不变。 It looks just like what you see in the above Debug message. 看起来就像您在上面的调试消息中看到的一样。

Does anyone know why esi 2 isn't getting parsed/included? 有谁知道为什么不解析/包含esi 2? Any help would be GREATLY appreciated! 任何帮助将不胜感激!

So apparently the ESI tag wasn't getting processed because it was inside a //[CDATA[ block. 显然,ESI标签没有得到处理,因为它位于// [CDATA [块]内。 I'm sure this has something to do with XML compliance. 我确信这与XML合规性有关。 I thought that setting esi_syntax=7 would prevent such a problem, but it turns out that that only affects the content of the ESI itself (it doesn't lift the safety checks for the code which does the including). 我认为设置esi_syntax = 7可以防止出现这样的问题,但事实证明这只会影响ESI本身的内容(它不会解除对包含这些内容的代码的安全检查)。

The solution will be to rework my application so that the ESI is its own self-contained script tag. 解决方案是重新处理我的应用程序,以便ESI是它自己的自包含脚本标记。

Try adding a backslash before the "&" in the querystring. 尝试在查询字符串中的“&”之前添加反斜杠。

At least with me Varnish ignores all parameters but the first one if you don't do it. 至少对于我来说,Varnish会忽略所有参数,但如果您不这样做,则会忽略第一个参数。

Eg: 例如:

Maybe you'll have problems with the "[" and "]" and they will also need a backslash. 也许你会遇到“[”和“]”的问题,他们也需要反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM