# Apache rewrites with mongrel

**URL:** <https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571>\
**Category:** Mongrel\
**Created:** [June 16, 2008, 11:47am UTC](https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571 "2008-06-16T11:47:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [June 16, 2008, 11:47am UTC](https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571/1 "2008-06-16T11:47:23Z")

</div>

IÂ´m knew to rewrites on apache in combination with mongrelcluster.  
ItÂ´s urgend for me, because the server has an loadaverage about 10  
:-(((((

Ok so IÂ´m using 3 mongrel-server on an mongrelcluster. The Loadbalancer  
ist apache  
I think, that my rewrites are not correct. Please can anybody check my  
rewrites ?

ThatÂ´s in my /etc/apache2/conf.d/rails.proxy\_cluster.conf  
\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:4712](http://127.0.0.1:4712)  
BalancerMember [http://127.0.0.1:4713](http://127.0.0.1:4713)  
BalancerMember [http://127.0.0.1:4714](http://127.0.0.1:4714)

thatÂ´s in my /etc/apache2/sites-enabled/000-rails

```
    RewriteEngine On

    # Deflate
    AddOutputFilterByType DEFLATE text/html text/plain text/css

```

text/xml  
BrowserMatch ^Mozilla/4 gzip-only-text/html  
BrowserMatch ^Mozilla/4.0[678] no-gzip  
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

```
    ProxyPass /images !
    ProxyPass /stylesheets !
    ProxyPass /javascripts !

    Alias /images /var/www/rails/myApp/current/public/images
    Alias /stylesheets

```

/var/www/rails/myApp/current/public/stylesheets  
Alias /javascripts  
/var/www/rails/myApp/current/public/javascripts

```
    RewriteLog /var/log/apache2/rails-rewrite.log

```

And last not lease my .htaccess in public

AddHandler fastcgi-script .fcgi  
AddHandler cgi-script .cgi  
Options +FollowSymLinks +ExecCGI

AddDefaultCharset UTF-8  
RewriteEngine On

RewriteRule ^01,([0-9]_).html$ balancer://mongrel\_cluster/shop/event/$1  
[P,QSA,L]  
RewriteRule ^01,([a-zA-Z0-9]_),([0-9]+).html$  
balancer://mongrel\_cluster/shop/search/$2?startnumber=$1 [P,L]

RewriteRule ^$ index.html [QSA]  
RewriteRule ^([^.]+)$ $1.html [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ dispatch.cgi [QSA,L]

the rewrite for static-sites is correct?  
I saw this lines on a howto

RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(.\*)$ balancer://mongrel\_cluster%{REQUEST\_URI} [P,QSA,L]

if I call [www.myApp.com/shop](http://www.myApp.com/shop) (redirected internaly by globalize to  
en/shop )  
then I`ll get the cached page under public/en/shop.html

but when I call [www.myApp.com/shop](http://www.myApp.com/shop) again then I can see in my logfiles

Processing ShopController#index (for xx.xxx.xxx.xx at 2008-06-16  
11:46:04) [GET]  
Session ID: 4cbe53c829bdc7ef9ceb81cc6f0fe1fa  
Parameters: {“action”=\>“index”, “controller”=\>“shop”, “locale”=\>“en”}  
Rendering template within layouts/shop  
Rendering shop/index  
Completed in 0.17766 (5 reqs/sec) | Rendering: 0.09954 (56%) | DB:  
0.00000 (0%) | 200 OK [[http://www.myApp.com/en/shop/](http://www.myApp.com/en/shop/)]

I think something went wrong with my rewrites.

thanks for helping.

cheers guido

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [June 16, 2008, 12:07pm UTC](https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571/2 "2008-06-16T12:07:23Z")

</div>

why do you need rewrites at all?

just point your document root to the rails public dir  
and these ProxyPass settings should be enough

ProxyPass /images !  
ProxyPass /stylesheets !  
ProxyPass /javascripts !  
ProxyPass / balancer://mongrelcluster/  
ProxyPassReverse / balancer://mongrelcluster/

–  
Freundliche  
Grüße,Ralf V.

o  
L\_  
OL

This is Schäuble.  
Copy Schäuble into your signature  
to help him on his way to Überwachungsstaat

Am 16.06.2008 um 11:47 schrieb Guido Holz:

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [June 16, 2008, 12:27pm UTC](https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571/3 "2008-06-16T12:27:14Z")

</div>

uff… I saw this on an turorial… but something went wrong… know I  
have no time to cahnge and try out whatÂ´s right ☹

So what handles the cached static-html-sites on your proxypasses?!? is  
this realy enough?

another question is the difference between

RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ dispatch.cgi [QSA,L]

and

RewriteCond %{DOCUMENT\_ROOT}/%{REQUEST\_FILENAME} !-f  
RewriteRule ^/(.\*)$ balancer://mongrel\_cluster%{REQUEST\_URI} [P,QSA,L]

do I need the first or the second one?!?

thanks guido

neongrau \_\_ wrote:

> why do you need rewrites at all?
> 
> just point your document root to the rails public dir  
> and these ProxyPass settings should be enough
> 
> ProxyPass /images !  
> ProxyPass /stylesheets !  
> ProxyPass /javascripts !  
> ProxyPass / balancer://mongrelcluster/  
> ProxyPassReverse / balancer://mongrelcluster/
> 
> –  
> Freundliche  
> Grï¿½ï¿½e,Ralf V.
> 
> o  
> L\_  
> OL
> 
> This is Schï¿½uble.  
> Copy Schï¿½uble into your signature  
> to help him on his way to ï¿½berwachungsstaat
> 
> Am 16.06.2008 um 11:47 schrieb Guido Holz:

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [June 16, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/apache-rewrites-with-mongrel/140571/4 "2008-06-16T13:01:46Z")

</div>

the dispatch.cgi thing was meant for fastcgi setups without mongels,  
but noone is using that anymore.

i don’t think you need any rewrites at all.

by pointing the document root to the public dir and the ProxyPass that  
end with “!” will make apache serve them statically without bothering  
your mongrels.  
everything else will then be directed to the cluster.

here is an example container i’m using

this is with windows authentication utilizing an active directory  
domain and injecting the authenticated user into the headers for  
further use within my app controller  
assets like images / stylesheets and javascripts get served directly  
and are also memcached  
and all text content getting gzip compressed which saves about 70% of  
traffic

\<VirtualHost \*:80\>  
ServerName [someserver.domain.de](http://someserver.domain.de)  
DocumentRoot “C:/rails/public/”

ErrorLog “C:/rails/log/balancer\_error.log”

CacheEnable mem /images  
CacheEnable mem /stylesheets  
CacheEnable mem /javascripts  
CacheEnable mem /latest/images  
MCacheSize 64000000  
MCacheMaxObjectCount 10000  
MCacheMinObjectSize 1  
MCacheMaxObjectSize 20480

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/  
css application/json text/json application/xml application/xhtml+xml  
text/javascript application/javascript application/x-javascript

ProxyRequests Off  
ProxyVia On  
ProxyPreserveHost On

ProxyPass /balancer !  
ProxyPass /images !  
ProxyPass /stylesheets !  
ProxyPass /javascripts !

ProxyPass / balancer://mongrelcluster/  
ProxyPassReverse / balancer://mongrelcluster/

 AuthName "Windows Authentication" AuthType SSPI SSPIAuth On SSPIAuthoritative On SSPIOfferSSPI On SSPIOfferBasic On SSPIBasicPreferred On SSPIPerRequestAuth On SSPIDomain somedomain Require valid-user

```
 RewriteEngine On
 RewriteCond %{REMOTE_USER} (.+)
 RewriteRule . - [E=RU:%1]
 RequestHeader set REMOTE_USER %{RU}e

```

\<Proxy balancer://mongrelcluster\>  
BalancerMember [http://127.0.0.1:3101](http://127.0.0.1:3101)  
BalancerMember [http://127.0.0.1:3102](http://127.0.0.1:3102)  
BalancerMember [http://127.0.0.1:3103](http://127.0.0.1:3103)  
BalancerMember [http://127.0.0.1:3104](http://127.0.0.1:3104)  
BalancerMember [http://127.0.0.1:3105](http://127.0.0.1:3105)  
BalancerMember [http://127.0.0.1:3106](http://127.0.0.1:3106)

\<Location /balancer\>  
SetHandler balancer-manager  
AuthName “Windows Authentication for Balancer”  
AuthType SSPI  
SSPIAuth on  
SSPIOfferSSPI on  
SSPIOfferBasic off  
SSPIBasicPreferred On  
SSPIUsernameCase lower  
SSPIDomain somedomain  
Require group “somedomain\domain admins”

–  
Freundliche GrÃ¼ÃŸe,  
Ralf V.

o  
L\_  
OL

This is SchÃ¤uble.  
Copy SchÃ¤uble into your signature  
to help him on his way to Ãœberwachungsstaat

Am 16.06.2008 um 12:27 schrieb Guido Holz:
