# Windows Production Apache Cluster. Mongrel sleeps

**URL:** <https://www.ruby-forum.com/t/windows-production-apache-cluster-mongrel-sleeps/164255>\
**Category:** Rails\
**Created:** [March 30, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/windows-production-apache-cluster-mongrel-sleeps/164255 "2009-03-30T15:13:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [March 30, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/windows-production-apache-cluster-mongrel-sleeps/164255/1 "2009-03-30T15:13:06Z")

</div>

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/](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](http://127.0.0.1:4004)  
BalancerMember [http://127.0.0.1:4005](http://127.0.0.1:4005)  
BalancerMember [http://127.0.0.1:4006](http://127.0.0.1:4006)  
BalancerMember [http://127.0.0.1:4007](http://127.0.0.1:4007)

\<VirtualHost \*:80\>  
ServerName \*\*\*\*\*\*\*\*\*\*\*\*  
DocumentRoot C:/websites/\*\*\*\*\*\*\*\*\*\*\*/

\<Directory C:/websites/\*\*\*\*\*\*\*\*\*\*/public/ \>  
Options Indexes FollowSymLinks MultiViews  
AllowOverride All  
Order allow,deny  
allow from all

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]

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?

---

<div class="post-metadata">

**Author:** ![chrisdwan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7feea3/32.png) [@chrisdwan](https://www.ruby-forum.com/u/chrisdwan)\
**Post date:** [April 1, 2009, 6:57pm UTC](https://www.ruby-forum.com/t/windows-production-apache-cluster-mongrel-sleeps/164255/2 "2009-04-01T18:57:43Z")

</div>

Anyone got any idea on how to tackle this problem?
