You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Igor Cicimov <ic...@gmail.com> on 2009/11/20 07:20:00 UTC
Re: [users@httpd] sending pre-compressed content through reverse
proxy using mod_rewrite
Write your own 404 page? Is that good enough?
On Fri, Nov 20, 2009 at 7:28 AM, Haroon Rafique
<ha...@utoronto.ca>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
> <ha...@utoronto.ca>
>
>
> ---------------------------------------------------------------------
> 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@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
[users@httpd] Re: sending pre-compressed content through reverse proxy using
mod_rewrite
Posted by Oliver Schoett <ol...@capgemini-sdm.com>.
Haroon Rafique wrote:
> It would be nice if I could just override
> the 404 error though.
>
I just did that using mod_asis. The .asis document can set its own
headers, including status:
Status: 200 OK
Content-Type: image/gif
Cache-Control: public, max-age=7200
Expires: Thu, 01 Jan 2009 00:00:00 GMT
Last-Modified: Sat, 20 Sep 2008 20:32:04 GMT
GIF89a[dummy image]
This is for an image server where URLs of missing images receive a dummy
image with status 200.
However, I did not succeed in setting a dynamic Expires: header using
mod_expires.
Regards,
Oliver Schoett
---------------------------------------------------------------------
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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] sending pre-compressed content through reverse
proxy using mod_rewrite
Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 10:12am, HR=>Haroon Rafique <ha...@utoronto.ca> 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 <ha...@utoronto.ca>
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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] sending pre-compressed content through reverse
proxy using mod_rewrite
Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 5:20pm, IC=>Igor Cicimov <ic...@gmail.com> 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
<ha...@utoronto.ca>
---------------------------------------------------------------------
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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org