https://wiki.uniformserver.com/index.php?title=Reverse_Proxy_Server_2:_mod_proxy_html_2&feed=atom&action=historyReverse Proxy Server 2: mod proxy html 2 - Revision history2024-03-29T00:21:30ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=Reverse_Proxy_Server_2:_mod_proxy_html_2&diff=3840&oldid=prevRic: New page: {{Nav reverse proxy server}} On the previous page I mentioned a Firefox error message “''The page you are trying to view cannot be shown because it uses an invalid or unsupported form o...2009-08-22T14:27:26Z<p>New page: {{Nav reverse proxy server}} On the previous page I mentioned a Firefox error message “''The page you are trying to view cannot be shown because it uses an invalid or unsupported form o...</p>
<p><b>New page</b></p><div>{{Nav reverse proxy server}}<br />
<br />
On the previous page I mentioned a Firefox error message “''The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.''“ This message is highlighting a server configuration problem I avoided an in-depth look at this issue by providing a partial solution.<br />
<br />
This page covers a complete solution in particular the root cause of the above issue.<br />
<br />
== Mod Deflate ==<br />
On the previous page a partial solution was to disable Mod Deflate on the back-end server. However; default installations of Uniform Sever Mod Deflate is enabled and for a very good reason it saves bandwidth.<br />
<br />
Edit file C:\server_b\UniServer\usr\local\apache2\conf\httpd.conf un-comment following line as shown '''LoadModule deflate_module modules/mod_deflate.so''' this enables gzip compression. The module automatically compresses files defined in the configuration block <IfModule mod_deflate.c></IfModule><br />
<br />
As a slight diversion it’s worth taking a look at this block in a little more detail. <br />
{|<br />
|-valign="top"<br />
|<br />
<pre><br />
<IfModule mod_deflate.c><br />
AddEncoding x-compress Z<br />
AddEncoding x-gzip gz tgz<br />
DeflateCompressionLevel 9<br />
AddOutputFilterByType DEFLATE text/html text/plain text/xml<br />
text/css application/javascript<br />
<br />
# Setup custom deflate log<br />
DeflateFilterNote Input instream<br />
DeflateFilterNote Output outstream<br />
DeflateFilterNote Ratio ratio<br />
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate<br />
#CustomLog logs/deflate.log deflate<br />
<br />
<Directory /><br />
# Insert filter<br />
SetOutputFilter DEFLATE<br />
# Netscape 4.x has some problems...<br />
BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
# Netscape 4.06-4.08 have some more problems<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
# MSIE masquerades as Netscape, but it is fine<br />
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html<br />
# Don't compress images<br />
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary<br />
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar|7z)$<br />
no-gzip dont-vary<br />
# Make sure proxies don't deliver the wrong content<br />
Header append Vary User-Agent env=!dont-vary <br />
</Directory><br />
</IfModule><br />
</IfModule><br />
</pre><br />
|<br />
<br /><br />
1) Use this directive to target files for compression:<br />
* Allow ONLY certain types of files using '''AddOutputFilterByType'''<br />
<br />
<br />
2) A pre-configured custom deflate log can be enabled<br />
* Un-comment line as shown: '''CustomLog logs/deflate.log deflate''' <br />
A file '''deflate.log''' is created in folder UniServer\usr\local\apache2\'''logs'''<br /><br />
Containing lines with the following format note the compression ratio<br />
*GET /about.html HTTP/1.1" 607/1283 47%<br />
*GET /links.html HTTP/1.1" 482/1152 41%<br />
<br />
<br />
3) Use this directive for Browser exclusions:<br />
* '''BrowserMatch''' <br />
<br />
<br />
4) Use this directive to exclude files from compression:<br />
* Allow ALL except certain file extensions using '''SetEnvIfNoCase'''<br />
<br />
<br />
5) To prevent storing two or more copies of the same file dependent on client request involving a proxy or cache server .<br />
* Use this directive: '''Header append Vary''' User-Agent env=!dont-vary<br />
|}<br />
<br />
'''''Note 1'':''' Two lines above should be on a single line as shown below:<br />
* AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript<br />
* SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar|7z)$ no-gzip dont-vary<br />
<br />
'''''Note 2'':''' Enable logging during test only. For production disable because file size quickly becomes large. <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Cause and Solution 3 ==<br />
Back to error message “The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.“<br />
{|<br />
|-valign="top"<br />
|<br />
<pre><br />
<VirtualHost *><br />
ServerName localhost:80<br />
DocumentRoot C:/server_a1/UniServer/www<br />
<br />
ProxyRequests off<br />
<Proxy *><br />
Order deny,allow<br />
Deny from all<br />
Allow from 127.0.0.1<br />
</Proxy><br />
<br />
ProxyPass /info/ http://localhost:82/<br />
ProxyHTMLURLMap http://localhost:82 /info<br />
<Location /info/><br />
ProxyPassReverse http://localhost:82/<br />
#SetOutputFilter proxy-html<br />
SetOutputFilter INFLATE;proxy-html;DEFLATE<br />
ProxyHTMLURLMap / /info/<br />
ProxyHTMLURLMap /info /info<br />
</Location><br />
<br />
<br />
</VirtualHost><br />
</pre><br />
|<br />
<br /><br />
The above error message is produced because compressed html files are passed to mod_proxy_html for processing. It thinks the page is malformed attempts correction resulting in a corrupt page.<br />
<br />
The deflate module is used for compressing text, HTML and XML. The output filter is set to '''DEFLATE''' (compress). However we want to use the 'proxy-html' output filter. Trouble is when SetOutputFilter is set to proxy-html it overrides DEFLATE.<br />
<br />
Page passed to mod proxy html remains compressed (deflated), links cannot be rewritten however the page is normalised in an attempt to correct this effectively corrupts the page.<br />
<br />
'''''Solution'':'''<br />
* Replace: '''SetOutputFilter proxy-html'''<br />
* With: '''SetOutputFilter INFLATE;proxy-html;DEFLATE'''<br />
** '''INFLATE''' decompress<br />
** '''proxy-html''' use mod proxy-html filter<br />
** '''DEFLATE''' compress file <br />
|}<br />
<br />
Although the above solution is a little more processor intensive it does allow you to minimise bandwidth when a back-end server is connected to the Internet.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Test ==<br />
A quick test.<br />
<br />
Edit configuration file:<br />
<br />
* C:\server_a\UniServer\usr\local\apache2\conf\httpd.conf<br />
* Disable line as shown: <nowiki>#</nowiki>SetOutputFilter proxy-html<br />
* Add line as shown above: '''SetOutputFilter INFLATE;proxy-html;DEFLATE'''<br />
<br />
Edit configuration file:<br />
<br />
* C:\server_b\UniServer\usr\local\apache2\conf\httpd.conf <br />
* Enable compression un-comment the line as shown:<br />
* LoadModule deflate_module modules/mod_deflate.so <br />
<br />
Restart both servers, type into browser '''<nowiki>http://localhost/info/</nowiki>''' all links will work as expected.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Template ==<br />
{|cellspacing="10"<br />
|-valign="top"<br />
|<br />
<pre><br />
<VirtualHost *><br />
ServerName localhost:80<br />
DocumentRoot C:/server_a1/UniServer/www<br />
<br />
ProxyRequests off<br />
<Proxy *><br />
Order deny,allow<br />
Deny from all<br />
Allow from 127.0.0.1<br />
</Proxy><br />
<br />
ProxyPass /info/ http://localhost:82/<br />
ProxyHTMLURLMap http://localhost:82 /info<br />
<Location /info/><br />
ProxyPassReverse http://localhost:82/<br />
SetOutputFilter INFLATE;proxy-html;DEFLATE<br />
ProxyHTMLURLMap / /info/<br />
ProxyHTMLURLMap /info /info<br />
</Location><br />
<br />
ProxyPass /wiki/ http://localhost:84/wiki/<br />
ProxyHTMLURLMap http://localhost:84/wiki /wiki<br />
<Location /wiki/><br />
ProxyPassReverse http://localhost:84/wiki/<br />
SetOutputFilter INFLATE;proxy-html;DEFLATE<br />
ProxyHTMLURLMap / /wiki/<br />
ProxyHTMLURLMap /wiki /wiki<br />
</Location><br />
<br />
ProxyPass /wordpress/ http://localhost:85/wordpress/<br />
ProxyHTMLURLMap http://localhost:85/wordpress /wordpress<br />
<Location /wordpress/><br />
ProxyPassReverse http://localhost:85/wordpress/<br />
SetOutputFilter INFLATE;proxy-html;DEFLATE<br />
ProxyHTMLURLMap / /wordpress/<br />
ProxyHTMLURLMap /wordpress /wordpress<br />
</Location><br />
<br />
ProxyPass /joomla/ http://localhost:86/joomla/<br />
ProxyHTMLURLMap http://localhost:86/joomla /joomla<br />
<Location /joomla/><br />
ProxyPassReverse http://localhost:86/joomla/<br />
SetOutputFilter INFLATE;proxy-html;DEFLATE<br />
ProxyHTMLURLMap / /joomla/<br />
ProxyHTMLURLMap /joomla /joomla<br />
</Location><br />
<br />
<br />
</VirtualHost><br />
</pre><br />
|<br />
<br /><br />
<br />
* The above solution makes for an easy to use template following is an example of what I mean.<br />
* It’s a copy and past exercise<br />
<br />
# Copy the first block<br />
# Paste below last block<br />
# Change the folder name<br />
# Change the server name<br />
# Repeat for each back-end server<br />
<br />
<br />
The example shows how symmetrical each block is. I have shown a typical solution that assumes each back-end server runs a dedicated application such as MediaWiki, Wordpress and Joomla.<br />
<br />
You can proxy many of the standard applications using this template since they require no special tweaks.<br />
<br />
That said some applications require special consideration for example an SVN server.<br />
<br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
The above shows how easy it is to proxy standard applications.<br />
<br />
With a minor tweak you can preserver compression between a proxy and backend server thus retaining precious bandwidth.<br />
<br />
I mentioned that certain applications require special consideration on the next page and [[Reverse Proxy Server 2: SVN | '''SVN server''']] is covered.<br />
<br />
'''''[[#top | Top]]'''''<br />
----<br />
<br />
{|<br />
|-valign="middle"<br />
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]] <br />
|}<br />
<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric