清漆 ESI 不工作

清漆 ESI 不工作

我有這樣的設定: - nginx 連接埠 80 - varnish (3.0.4) 連接埠 6081 - apache 連接埠 8080

Nginx 接收請求並將其傳遞給 Varnish,然後 Varnish 檢查緩存,然後從快取返回回應或將請求傳遞給 Apache。在 Apache 中,我停用了 mod_deflate,因此輸出不會被壓縮。在 Varnish 內部,我為所有請求啟用了 ESI,如下所示:

sub vcl_fetch {
    set beresp.do_esi = true;
}

我的測試檔案(test.php)如下所示:

Current time is: <esi:include src="/date.php" /> 

日期.php:

<?php
echo date('H:i:s');

但 Varnish 不處理 esi 包含的內容。在 varnishlog 中我收到此錯誤:

11 ESI_xmlerror c No ESI processing, first char not '<'

來自 test.php 的回應標頭:

Accept-Ranges:bytes
Age:3
Connection:keep-alive
Content-Length:51
Content-Type:text/html
Date:Sun, 01 Sep 2013 11:51:57 GMT
Server:nginx
Surrogate-Control:"ESI/1.0"
Via:1.1 varnish
X-Powered-By:PHP/5.4.15-1~precise+1
X-Varnish:1236304062 1236304061

以及 html 輸出:

Current time is: <esi:include src="/name.php" /> 

所以你可以看到ESI沒有被處理。

我究竟做錯了什麼?

答案1

解決了...如果伺服器回應的第一個字元不是“<”,ESI 將無法運作。

<html>
<head>
    <title></title>
</head>
<body>
Current time is: <esi:include src="/name.php" /> 
</body>
</html>

答案2

另一種方法是使用參數來執行 Varnish 守護程式:

-p esi_syntax 0x3

意思是

0x00000001 - Don't check if it looks like XML
0x00000002 - Ignore non-esi elements

相關內容