Grepular

Apache Forward Proxying with Compression

Written 7 years ago by Mike Cardwell

Up until recently I have been using Squid as a caching web proxy. I’d heared that Apaches mod_proxy was capable of doing forward proxying, but I had no reason to change over, other than being able to remove an extra service from my box; I was already running both servers, but Apache was just serving websites.

I’ve been stuck using 3G for my Internet access for the past few days though, which is quite a bit slower than broadband, so it made me wonder if Squid was adding gzip compression to the responses. It wasn’t, and as far as I can see, there is no option to make it do so. So I figured I would try out using Apache instead. Here’s the vhost I came up with:

<VirtualHost *:3128>
  <Proxy *>
    Order Deny,Allow
    Deny from all
    Allow from 10.0.0.0/8
  </Proxy>
  ProxyRequests On
</VirtualHost>

My laptop appears on the 10.0.0.0/8 network when accessing the proxy over the Internet, because I’m using a VPN in the middle. I also have the following server wide configuration to add compression:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

SetOutputFilter DEFLATE

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$            no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$                          no-gzip dont-vary

BrowserMatch ^Mozilla/4         gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE             !no-gzip !gzip-only-text/html

Header append Vary User-Agent env=!dont-vary

This works brilliantly. I now have a forwarding proxy, which gives me gzip compression over the 3G connection, even if the web server I’m ultimately connecting to doesn’t use the gzip Content-Encoding. I should also be able to add the JavaScript minification and CSS minification modules that I wrote about recently to improve the speed even more, but I haven’t got around to that yet.

You can follow this Blog using RSS or . To read more, visit my blog index.

Feeling generous?BitcoinMoneroZcashPaypal