Re: sending pre-compressed content through reverse proxy using mod_rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Write your own 404 page? Is that good enough?


On Fri, Nov 20, 2009 at 7:28 AM, Haroon Rafique <haroon.rafique@xxxxxxxxxxx> wrote:
Hi there,

I am running a reverse proxy (using mod_proxy) and I would like to internally rewrite (using mod_rewrite) certain files and instead send their pre-compressed .gz versions. I have minified and compressed versions of .js and .css files available with .gz extensions (using yuicompressor, if it matters) through the proxied backend. The files may or may not be physically located on the reverse proxy (depending on whether the backend is running on the same machine or not). This is what has worked for me as follows:

RewriteEngine On

# static .js files should be internally redirected to gzipped ones
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_URI} ^/rxp/.+\.js$
RewriteRule ^(.+\.js)$ proxy:balancer://glassfishcluster$1.gz [E=gz:gz,E=jsgz:jsgz,L]

# static .css files should be internally redirected to gzipped ones
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_URI} ^/rxp/.+\.css$
RewriteRule ^(.+\.css)$ proxy:balancer://glassfishcluster$1.gz [E=gz:gz,E=cssgz:cssgz,L]

# set some headers for gzipped content
Header set Content-Encoding gzip env=gz
Header set Content-Type text/_javascript_ env=jsgz
Header set Content-Type text/css env=cssgz

The above works well so far. The Content-Encoding and the Content-Type headers are okay as well. The only problem is if the requested URL is not available (e.g., typo). Then I do get a 404, but since the Content-Encoding header still says gzip, the browser displays:

       * Content Encoding Error
         The page you are trying to view cannot be
         shown because it uses an invalid or unsupported form of
         compression.

Any way around the "improper" 404 screen? In general, is my rewrite strategy above somewhat sound? Comments, thoughts are welcome.

This is on RHEL Server 5.3.

Server version: Apache/2.2.14 (Unix)
Server built:   Nov 17 2009 16:38:48

Compiled in modules:
 core.c
 worker.c
 http_core.c
 mod_so.c

Thanks,
--
Haroon Rafique
<haroon.rafique@xxxxxxxxxxx>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
 "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux