11 August 2008

apache 2, mod_proxy, load balancer, mongrel_cluster, rails, and 404

I don't know where the bug is, but the fix had nothing to do with mongrel or rails. For some pages, most of the time I would get a 404 Not Found error. The apache error log showed this:

[Sun Aug 10 20:54:48 2008] [error] [client a.b.c.d] proxy: error reading status line from remote server, referer: http://triplex.softify.com/
[Sun Aug 10 20:54:48 2008] [error] [client a.b.c.d] proxy: Error reading from remote server returned by /user/list, referer: http://triplex.softify.com/

After much googling I ended up on the page that says it all, and more besides: https://issues.apache.org/bugzilla/show_bug.cgi?id=37770

Two config modifications stand out: firstly, to add these lines -

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1

and secondly, to set the log level to debug:

LogLevel debug

I added both and the situation is much improved. The worst offender is a very slow-loading page.

I'm on apache 2.2.6. I'd love to know what the correct fix is. Interestingly, according to the bugzilla page for bug 37770, this has been an issue since 2.2.2.

This is how my mongrel_cluster apache virtual host proxy load-balancer config looks now:

<VirtualHost *:80>
        ServerName triplex.softify.com
        DocumentRoot /u/apps/triplex/current/public
        RewriteEngine On

        <Proxy balancer://mongrelcluster>

        # Redirect all non-static requests to Mongrel
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
        RewriteRule ^/(.*)$ balancer://mongrelcluster%{REQUEST_URI} [P,QSA,L]

        ProxyPass / balancer://mongrelcluster/
        ProxyPassReverse / balancer://mongrelcluster/
        ProxyPreserveHost on

        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1

        <Proxy *>
         Order deny,allow
         Allow from all

        ErrorLog /var/log/apache2/triplex.softify.com.error.log
        CustomLog /var/log/apache2/triplex.softify.com.access.log combined
        LogLevel debug

No comments:

Post a Comment