Search code examples
apachemod-proxymod-include

Garbled text when including remote .shtml file using mod_include and mod_proxy


I'm experimenting with apache mod_include.

I got two servers running apache: I'm trying to include in my test_local.shtml (server1) some simple text from 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>

At first it didn't work (got "File does not exist" error in error_log). It looks like that for security reasons the only files I manage to include are on my local server (server1), with a local path, but not a remote url. Then I understood that I needed to use mod_proxy (and mod_proxy_html) in combination with mod_include to make remote inclusion work.

So I added the following to my httpd.conf (on server1):

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

Then I changed the include line in test_local.shtml to:

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

No errors this time, something gets included, but the resulting text is all garbled:

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

Am I missing something in my configuration? What's wrong?

UPDATE: I suspect it's something about the way data is sent (and then read) between the two servers.. such as compression or similar. I checked mod_deflate configuration section, which is included and working in both servers, and it's the same. Any idea? Thanks

UPDATE 2: disabling SetOutputFilter DEFLATE on server2, the text included with mod_include on server1 is perfectly readable. So that's the source of the issue: how can I configure server1 to handle the gzipped content and display it correctly? (Hypotetically I'd imagine some sort of inputfilter opposed to outputfilter..)


Solution

  • I found two solutions, but I prefer the second one because it doesn't need to change the configuration of the remote server.

    Solution 1:

    By adding the following to the remote server configuration, we disable the gzip compression for .shtml files:

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

    This is not the best solution for me, because I don't have always access to the remote server from which I include contents.

    Solution 2:

    On the "local" server (the one hosting pages that use SSI inclusion), adding the following:

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

    Basically, I'm telling Apache to disable the Accept-Encoding request header; when requesting .shtml pages to the remote server, we ask the page without compression. Consequently, we get plain text, avoiding the garbled content.

    Further info: http://wiki.apache.org/httpd/ReInflating