2013-02-19 97 views
2

我正在嘗試使用apache mod_include。我試圖在我的test_local.shtml(server1)中包含一些來自test_remote.shml(server2)的簡單文本。使用mod_include和mod_proxy包含遠程.shtml文件時出現亂碼文本

test_local.shtml

<html> 
    <head> 
    <title></title> 
    </head> 
    <body> 
    <!--#include virtual="http://www.server2.com/test_remote.shtml"--> 
    </body> 
</html> 

test_remote.shtml

<b>this is a test</b> 

起初,它沒有工作(有 「文件不存在」 錯誤error_log中)。 看起來出於安全原因,我管理的唯一文件位於本地服務器(server1)上,具有本地路徑,但不是遠程URL。 然後我明白我需要將mod_proxy(和mod_proxy_html)與mod_include結合使用,以實現遠程包含工作。

所以我增加了以下我的httpd.conf(Server1上):

ProxyPass /server2 http://www.server2.com 

然後,我改變了包括test_local.shtml到行:

<!--#include virtual="/server2/test_remote.shtml"--> 

沒有錯誤這一次,東西得到包括,但由此產生的文字全是亂碼:

‹³I²+ÉÈ,V¢D…’Ôâý$;.j¿è 

我在配置中丟失了什麼?怎麼了?

更新:我懷疑這是兩個服務器之間發送(然後讀取)數據的方式,如壓縮或類似的。我檢查了mod_deflate配置部分,它包含在兩個服務器中,並且都是一樣的。任何想法?謝謝

UPDATE 2:禁用server2上的SetOutputFilter DEFLATE,server1上的mod_include包含的文本是完全可讀的。所以這就是問題的根源:我如何配置server1來處理gzip內容並正確顯示它? (Hypotetically我想像某種inputfilter反對outputfilter ..)

回答

2

我發現了兩種解決方案,但我更喜歡第二個,因爲它不需要更改遠程服務器的配置。

解決方案1:

加入以下到遠程服務器的配置,我們禁用gzip壓縮的文件的.shtml:

<IfModule mod_deflate.c> 
    SetEnvIfNoCase Request_URI \.shtml$ no-gzip dont-vary 
</IfModule> 

這不是對我最好的解決方案,因爲我並不總是可以訪問包含內容的遠程服務器。

解決方案2:

在 「本地」 服務器(一個主機使用SSI包含頁),增加以下內容:

ProxyPass /server2 http://www.server2.com/ 
ProxyPassReverse /server2 http://www.server2.com/ 
<Location "/server2/"> 
    RequestHeader unset Accept-Encoding 
</Location> 

基本上,我告訴阿帕奇禁用Accept-Encoding請求頭;當向遠程服務器請求.shtml頁面時,我們問頁面而不壓縮。因此,我們可以獲得純文本,避免出現亂碼。

更多信息:http://wiki.apache.org/httpd/ReInflating

相關問題