When running production mode on Windows 2003 using Apache and a proxy balancer mod and mod_rewrite to redirect to the mongrel instances, I sometimes get a Proxy Error thrown from Apache.
Setup is done according to this guide: http://nlakkakula.wordpress.com/2008/11/24/10-steps-for-deploying-your-ruby-on-rails-application-on-a-windows-server-2008-apache-mongrel-cluster/
4 Mongrel processes run as Windows Services on high ports (4000+)
VHost entry:
<Proxy balancer://ruby_cluster> BalancerMember http://127.0.0.1:4004 BalancerMember http://127.0.0.1:4005 BalancerMember http://127.0.0.1:4006 BalancerMember http://127.0.0.1:4007 </Proxy>
<VirtualHost *:80> ServerName ************ DocumentRoot C:/websites/***********/
<Directory C:/websites/**********/public/ > Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
ErrorLog C:/websites/**********/log/apache_error.log LogLevel warn
CustomLog C:/websites/**********/log/apache_access.log combined
RewriteEngine On
# Check for maintenance file and redirect all requests RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [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://ruby_cluster%{REQUEST_URI} [P,QSA,L] </VirtualHost>
Now this all works fine. Apache gets hit on port 80 like normal and redirects its request to one of the 4 mongrel services which will render the appropriate response.
However when the website hasn't seen traffic in a long while, lets say roughly 24 hours, the first hit always results in a 502 Proxy Error from apache:
Proxy Error
The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /.
Reason: Error reading from remote server
Refreshing the page will display the ruby generated page correctly again.
It seems that Mongrel falls asleep or something like that and will react either too late or with an invalid response when queried by Apache.
Does anyone have any advice on how to counter this problem?