lorrimanhg
07-16-2007, 09:40 PM
Hi Folks,
If the previous post seemed to stretch the definition of "Share Knowledge", this one won't.
The VPS came with a default Apache load-balanced Mongrel/Rails setup.
I noticed that if I stopped my mongrel instances I could still see my index.html file, as served up by Apache, but it was missing it's graphics and also it's stylesheets, which should also have been served up by Apache as they are static files. It appears that the mongrel instances had been handling static files, which they can do but are not as efficient as Apache. And that meant a config problem.
It turns out that the ProxyPass and ProxyPassReverse apache config lines needed removing (and would in anycase only work if placed before certain other lines). They are a hangover from the single-instance, non-load-balanced config. The 'rewrite' lines, lower down, use the [P] option to do the necessary reverse proxying, and the Proxy lines were causing an interference of some sort.
It may be that I am missing a trick or two since I am not an experienced Apache chap, but the stuff below reflects the configs listed on the Mongrel site (which itself is somewhat confusing: it took me a long time to realise the ProxyPass lines where not needed), and seem to fix the problem.
Final working apache config :
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/test
<Directory "/var/www/test"> #this line had "testapp" instead of "test" , confusingly
AllowOverride None
Order allow,deny
Allow from all
Options +FollowSymLinks
</Directory>
#the reverse proxying doesn't need this, and it has security implications- so switch off
ProxyRequests off
ErrorLog /var/www/test/log/apache_error_log
CustomLog /var/www/test/log/apache_access_log "combined"
# Configure mongrel_cluster
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
</Proxy>
# These directories should always be served up by Apache, since they contain static content.
#NOW COMMENTED OUT AS THEY ARE BOGUS
#ProxyPass /images !
#ProxyPass /stylesheets !
#ProxyPass /javascripts !
#ProxyPass /favicon.ico !
#ALSO CAUSING TROUBLE
#ProxyPass / balancer://mongrel_cluster/
#ProxyPassReverse / balancer://mongrel_cluster/
RewriteEngine on
# Important rule to prevent exposure of subversion files if you are deploying with Capistrano !
RewriteRule ^(.*/)?.svn/ - [F,L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
LogLevel warn
If the previous post seemed to stretch the definition of "Share Knowledge", this one won't.
The VPS came with a default Apache load-balanced Mongrel/Rails setup.
I noticed that if I stopped my mongrel instances I could still see my index.html file, as served up by Apache, but it was missing it's graphics and also it's stylesheets, which should also have been served up by Apache as they are static files. It appears that the mongrel instances had been handling static files, which they can do but are not as efficient as Apache. And that meant a config problem.
It turns out that the ProxyPass and ProxyPassReverse apache config lines needed removing (and would in anycase only work if placed before certain other lines). They are a hangover from the single-instance, non-load-balanced config. The 'rewrite' lines, lower down, use the [P] option to do the necessary reverse proxying, and the Proxy lines were causing an interference of some sort.
It may be that I am missing a trick or two since I am not an experienced Apache chap, but the stuff below reflects the configs listed on the Mongrel site (which itself is somewhat confusing: it took me a long time to realise the ProxyPass lines where not needed), and seem to fix the problem.
Final working apache config :
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/test
<Directory "/var/www/test"> #this line had "testapp" instead of "test" , confusingly
AllowOverride None
Order allow,deny
Allow from all
Options +FollowSymLinks
</Directory>
#the reverse proxying doesn't need this, and it has security implications- so switch off
ProxyRequests off
ErrorLog /var/www/test/log/apache_error_log
CustomLog /var/www/test/log/apache_access_log "combined"
# Configure mongrel_cluster
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:3000
BalancerMember http://127.0.0.1:3001
</Proxy>
# These directories should always be served up by Apache, since they contain static content.
#NOW COMMENTED OUT AS THEY ARE BOGUS
#ProxyPass /images !
#ProxyPass /stylesheets !
#ProxyPass /javascripts !
#ProxyPass /favicon.ico !
#ALSO CAUSING TROUBLE
#ProxyPass / balancer://mongrel_cluster/
#ProxyPassReverse / balancer://mongrel_cluster/
RewriteEngine on
# Important rule to prevent exposure of subversion files if you are deploying with Capistrano !
RewriteRule ^(.*/)?.svn/ - [F,L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
LogLevel warn