apache - 使用 mod_include 和 mod_proxy 包含远程 .shtml 文件时出现乱码

标签 apache mod-proxy mod-include

我正在尝试使用 apache mod_include。

我有两台运行 apache 的服务器:我试图在 test_local.shtml (server1) 中包含来自 test_remote.shml (server2) 的一些简单文本。

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 配置部分,该部分包含在两个服务器中并在其中工作,并且它是相同的。任何想法?谢谢

更新2:在server2上禁用SetOutputFilter DEFLATE,server1上mod_include包含的文本完全可读。这就是问题的根源:如何配置 server1 来处理 gzip 压缩的内容并正确显示它? (假设我会想象某种与输出过滤器相反的输入过滤器..)

最佳答案

我找到了两种解决方案,但我更喜欢第二种,因为它不需要更改远程服务器的配置。

解决方案 1:

通过将以下内容添加到远程服务器配置中,我们禁用 .shtml 文件的 gzip 压缩:

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

基本上,我告诉 Apache 禁用 Accept-Encoding 请求 header ;当向远程服务器请求 .shtml 页面时,我们请求未压缩的页面。因此,我们得到的是纯文本,避免了乱码内容。

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

关于apache - 使用 mod_include 和 mod_proxy 包含远程 .shtml 文件时出现乱码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14960347/

相关文章:

PHP max_execution_time 没有超时

apache - 干净的URL重定向循环

php - file_get_contents/curl 阻止其他客户端

java - 在 apache tomcat 中部署除 webapp 文件夹以外的 Web 应用程序

apache - httpd mod_proxy_balancer 故障转移 failonstatus - 透明切换

apache - 上传文件时mod_proxy 502代理错误

ssl - 配置 apache 服务器代理 SSL 连接时遇到问题

linux - SSI 和 lighttpd