2012-04-10 39 views
1

我正在嘗試設置光油以處理ESI包含在本地環境中。光油未處理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中添加了以下c onfig到文件底部:

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" /> 

ie。 ESI在標記中顯示,它未被處理。

我檢查了清漆日誌,但是在那裏沒有錯誤,沒有與ESI相關的任何錯誤。

任何人都可以看到我在做什麼錯在這裏?讓我知道是否需要更多信息..謝謝

+0

您是否使用光油> 3.0?因爲你正在使用新的語法... – ivy 2012-04-10 16:57:55

回答

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; 
     } 
} 

我現在正在做同樣的事情,所以試試看,讓我知道它是否適用於你。

+2

這是如何或其他答案的答案? OP(和我)想要包含來自同一服務器的東西,即使'sub vcl_fetch'包含'set beresp.do_esi = true;'varnish並不打擾向後端發出包含請求,只是將esi標籤轉儲到響應。這在谷歌顯示高,但我不明白這個或其他答案如何實際上是一個答案。 – HMR 2014-06-24 06:20:46

1

清漆只實施了一小部分ESI。截至2.1三個ESI語句:

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

基於變量和cookie的內容替換未實現,但在路線圖上。 光油不會在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   */ 
} 

}

1

對於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