Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a setup with Apache2 as a front-end server for multiple python apps served by gunicorn. My Apache2 setup using mod_proxy looks like this:

<VirtualHost *:80>
    UseCanonicalName On
    ServerAdmin webmaster@localhost

    LogLevel warn
    CustomLog /var/log/apache2/ combined
    ErrorLog /var/log/apache2/
    ServerSignature On

    Alias /media/ /home/example/

    ProxyPass /media/ !
    ProxyPass /
    ProxyPassReverse /
    ProxyPreserveHost On
    ProxyErrorOverride Off

Generally, this setup works pretty well. I have one problem though: When I restart the gunicorn process (takes 2-5 seconds) and there is a request from Apache, that request will fail with a 503 error. So far so good. But Apache keeps returning 503 errors, even after the gunicorn process is back up. It resumes serving content from the proxied server only after a full restart of Apache.

Is there a way around this behaviour?

share|improve this question
up vote 22 down vote accepted

Add retry=0 to your ProxyPass lines:

ProxyPass / retry=0

From the mod_proxy documentation:

Connection pool worker retry timeout in seconds. If the connection pool worker to the backend server is in the error state, Apache will not forward any requests to that server until the timeout expires. This enables to shut down the backend server for maintenance, and bring it back online later. A value of 0 means always retry workers in an error state with no timeout.

share|improve this answer
Thank you so much! Works perfectly :) You'll get the bounty in a couple of hours when I'm allowed to award it. – Benjamin Wohlwend May 7 '11 at 21:47
I believe you now want this link instead - the quoted paragraph seems to be missing from the version linked in the answer, and no mention of the retry option is made. For others wondering the same thing: the default value for this parameter is 60 seconds. – Gijs Nov 2 '12 at 14:14

Are you following the documented method for restarting gunicorn?

I would recommend a simple approach. If 2-5 seconds is acceptable downtime in your environment, then might I suggest simply scripting the Apache service to restart immediately after you restart your gunicorn service?

In a production environment, I would suggest using HAProxy instead of Apache as your front-end, and you might have much better luck.

share|improve this answer
Thanks for your answer! I use supervisord to control my gunicorn processes, my supervisor.conf looks basically like the example in the gunicorn repo. Unfortunately, I can't move away from Apache as a front-end server for organizational reasons. – Benjamin Wohlwend May 7 '11 at 14:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.