Apache’s mod_fastcgi and mod_deflate troubles

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 08, 2014

Follow me on Twitter as @mattiasgeniar

There’s a very old outstanding but in Apache’s mod_fastcgi combined with mod_deflate, where the Content-Length header is not being passed along properly between the FastCGI process (like PHP) and the compression performed by mod_deflate.

The problem occurs when your Apache webserver is running gzip compression via mod_deflate on the content, which is then being passed via mod_fastcgi to an upstream (like PHP) that tries to handle compression as well. In the case of a Drupal system, this can happen when you let Drupal handle gzip-compression via its Performance settings as well as Apache via its mod_deflate module.

And if you search the interwebs, you’ll find lots of reports on this;

These all go way back, to beyond 2010. So it’s safe to say, this problem has been around for some time. The suggestions to upgrade to the latest version of FastCGI don’t seem to help either, at least not on my test-system.

My current workaround was just to disable mod_deflate entirely in Apache, and handle the Gzip compression in another service (like Varnish as HTTP cache or in Nginx as my SSL terminator). This is far from pretty, but it got the job done. For now.

If anyone has any clues why mod_deflate together with mod_fastcgi can cause these headaches, I’d love to hear your thoughts and ideas.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.