Forum: Mongrel Apache rewrites with mongrel

2bff2eebb0a5bdccd3fb3156c345b413?d=identicon&s=25 Guido Holz (der_guido)
on 2008-06-16 11:47
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
  BalancerMember http://127.0.0.1:4713
  BalancerMember http://127.0.0.1:4714
</Proxy>

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 (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 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/]

I think something went wrong with my rewrites.


thanks for helping.

cheers guido
F12532c1224ff2ab2260e853258deddb?d=identicon&s=25 neongrau __ (neongrau)
on 2008-06-16 12:07
(Received via mailing list)
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 Vitasek


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:
2bff2eebb0a5bdccd3fb3156c345b413?d=identicon&s=25 Guido Holz (der_guido)
on 2008-06-16 12:27
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 Vitasek
>
>
> 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:
F12532c1224ff2ab2260e853258deddb?d=identicon&s=25 neongrau __ (neongrau)
on 2008-06-16 13:01
(Received via mailing list)
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
   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/

   <Proxy>
     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>

   <Proxy balancer://mongrelcluster>
     BalancerMember http://127.0.0.1:3101
     BalancerMember http://127.0.0.1:3102
     BalancerMember http://127.0.0.1:3103
     BalancerMember http://127.0.0.1:3104
     BalancerMember http://127.0.0.1:3105
     BalancerMember http://127.0.0.1:3106
   </Proxy>

   <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"
   </Location>

</VirtualHost>


--
Freundliche Grüße,
Ralf Vitasek


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:
This topic is locked and can not be replied to.