Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Users

sending pre-compressed content through reverse proxy using mod_rewrite

 

 

Apache users RSS feed   Index | Next | Previous | View Threaded


haroon.rafique at utoronto

Nov 19, 2009, 12:28 PM

Post #1 of 4 (584 views)
Permalink
sending pre-compressed content through reverse proxy using mod_rewrite

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 [at] utoronto>


---------------------------------------------------------------------
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 [at] httpd
" from the digest: users-digest-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


icicimov at gmail

Nov 19, 2009, 10:20 PM

Post #2 of 4 (559 views)
Permalink
Re: sending pre-compressed content through reverse proxy using mod_rewrite [In reply to]

Write your own 404 page? Is that good enough?


On Fri, Nov 20, 2009 at 7:28 AM, Haroon Rafique
<haroon.rafique [at] utoronto>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 [at] utoronto>
>
>
> ---------------------------------------------------------------------
> 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 [at] httpd
> " from the digest: users-digest-unsubscribe [at] httpd
> For additional commands, e-mail: users-help [at] httpd
>
>


haroon.rafique at utoronto

Nov 20, 2009, 7:12 AM

Post #3 of 4 (548 views)
Permalink
Re: sending pre-compressed content through reverse proxy using mod_rewrite [In reply to]

On Today at 5:20pm, IC=>Igor Cicimov <icicimov [at] gmail> wrote:

IC> Write your own 404 page? Is that good enough?
IC>

Hi Igor,

Thanks for your response. I tried adding the following (is that what you
had in mind?):

# set custom 404 in case .gz is not available
<LocationMatch "^/rxp.+\.(css|js)$">
ErrorDocument 404 "The requested URL was not found on this server."
</LocationMatch>

but I am still getting (Content-Encoding: gzip and Content-type:
text/javascript is the problem):

HTTP/1.1 404 Not Found
Date: Fri, 20 Nov 2009 15:04:15 GMT
Server: Sun GlassFish Enterprise Server v2.1
X-Powered-By: Servlet/2.5
Content-Type: text/javascript
Content-Language:
Content-Length: 1018
Content-Encoding: gzip
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
2009-11-20 10:04:17 ERROR 404: Not Found.

Ideas?

Cheers,
--
Haroon Rafique
<haroon.rafique [at] utoronto>


---------------------------------------------------------------------
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 [at] httpd
" from the digest: users-digest-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


haroon.rafique at utoronto

Nov 20, 2009, 7:27 AM

Post #4 of 4 (550 views)
Permalink
Re: sending pre-compressed content through reverse proxy using mod_rewrite [In reply to]

On Today at 10:12am, HR=>Haroon Rafique <haroon.rafique [at] utoronto> wrote:

HR> Hi Igor,
HR>
HR> Thanks for your response. I tried adding the following (is that what you
HR> had in mind?):
HR>
HR> # set custom 404 in case .gz is not available
HR> <LocationMatch "^/rxp.+\.(css|js)$">
HR> ErrorDocument 404 "The requested URL was not found on this server."
HR> </LocationMatch>
HR>
HR> [..snip..]

Hi Igor,

Immediately after writing this email, I tried:

ProxyErrorOverride On

and that seems to do the trick. It would be nice if I could just override
the 404 error though.

Cheers,
--
Haroon Rafique <haroon.rafique [at] utoronto>
Web Dude 416-946-5080
Enterprise Apps & Solutions Integration, University of Toronto

---------------------------------------------------------------------
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 [at] httpd
" from the digest: users-digest-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd

Apache users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.