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> ServerName example.com UseCanonicalName On ServerAdmin webmaster@localhost LogLevel warn CustomLog /var/log/apache2/example.com/access.log combined ErrorLog /var/log/apache2/example.com/error.log ServerSignature On Alias /media/ /home/example/example.com/pysrc/project/media/ ProxyPass /media/ ! ProxyPass / http://127.0.0.1:4711/ ProxyPassReverse / http://127.0.0.1:4711/ ProxyPreserveHost On ProxyErrorOverride Off </VirtualHost>
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?