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 VPS running nginx 1.1.19, php-fpm 5.3.10, and APC 3.1.9. The server is primarily running PHP scripts (vB, SMF, IPB) I'm also using Cloudflare as a CDN if that matters.

From what I can tell, there are 3 options for compression and I'm not sure which are redundant with each other or if they all are and which service should be handling it.

nginix has gzip, php-fpm has zlib, and the PHP scripts themselves have gzip. I feel I've seen in a lot of documentation that if a web server (nginx) is handling gzip, the PHP scripts shouldn't. Should zlib in php-fpm be enabled along with gzip or are they technically the same thing? I saw one source that said gzip/mod_deflate with zlib_compression is redundant and unnecessarily using CPU cycles, but my vB installation seems to run smoother when zlib and gzip are both enabled.

Does anyone know of the most efficient combination/arrangement of compression for this setup?

share|improve this question

I'm not sure what happens if you enable compression in multiple layers, but I would enable it in the topmost layer, i.e. Nginx. This catches dynamically produced PHP content, but also static content that is served directly by Nginx. I see compression as one of the final output filters before sending the content to the client.

share|improve this answer

You will want to use gzip in nginx and disable gzip in the web application you are using. Having both enabled will cause gzip to break.
Cloudflare by my experience only slowed down the website (static content was served slowly at peak hours), but if I remember correctly, Cloudflare has a compression (gzip) option as well.

Both the zlib and gzip formats use the same compressed data format internally, but have different headers and trailers around the compressed data.
The zlib format on the other hand was designed for in-memory and communication channel applications, and has a much more compact header and trailer and uses a faster integrity check than gzip.

Instead of APC, you might want to consider trying eAccelerator. Many users reported that it performs better than APC.

If you want to optimize further, have a look at Google PageSpeed and YSlow. They certainly helped me a lot in optimizing my websites!

share|improve this answer
Having both should not cause nginx to break. – rvs May 5 '12 at 6:03
No particular combination of them has caused anything to break as far as I can tell, but I know they will try to compress each other's compressed output and waste resources in the process. This is more of a question of efficiency. Xen- would you suggest having nginx's gzip compression and PHP's zlib compression both on then? My main reason for using Cloudflare is to save bandwidth on my own server for serving images. It seems like the best settings would be to disable nginx's gzip, enable zlib, and enable the minifying features on Cloudflare, but I could be wrong. – nuceman May 5 '12 at 17:32

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.