I'm using nginx reverse proxy cache with gzip enabled. However, I got some problems from Android applications HTTP-requests to my Rails JSON web service. It seems when I turn off reverse proxy cache, it works ok because the response header comes without gzip. Therefore, I think the problem is caused by gzip. What is the most appropriate level of gzip compression?

4 Answers
4

The level of gzip compression simply determines how compressed the data is on a scale from 1-9, where 9 is the most compressed. The trade-off is that the most compressed data usually requires the most work to compress/decompress, so if you have it set fairly high on a high-volume website, you may feel its effect.

It sounds like your issues are more related to the HTTP headers on the requests. Usually gzip-compressed HTTP traffic is accompanied by the Content-Encoding: gzip header. If this is being dropped somewhere, then the client might not know to have to decompress the response.

Yeah, I added the header Accept-Encoding with empty string with poster addon on mozilla, and the response back without Content-Encoding: 'gzip'. However, on the android app, it always returns back in gzip. I checked what has been cached in the proxy cache directories, nginx caches the gzip content, so it's probably responses back in gzip. How to solve this?
– ChamnapMar 30 '11 at 9:03

Some sources suggest that the decompression resources do not increase as the compression level increases. Resources actually decrease in some cases as the compression level increases. stackoverflow.com/questions/28452429/…
– user2208096Oct 9 '18 at 20:51

I'm not sure how representative this is but it should serve as an example. Also, I haven't taken the CPU usage into account but from these results the ideal compression level seems to be between 4 and 6.

Additionally, if you use the gzip_static module, you may want to pre-compress your files (in PHP):

Cloud you explain what's wrong about that? Anyways, I updated the answer, I researched a bit more and I see that sites like Amazon CloudFront uses a compression level of 6, probably because it's best about decompression speed (thus pages will load faster).
– DiegoGJul 27 '18 at 17:16

1) The difference between 2 and 6 is non trivial, it can up to 10-15%, look at the data or try it yourself. 2) the level of compression doesn't affect the difficulty to decompress (see stackoverflow.com/questions/28452429/…)
– calumbrodieJul 28 '18 at 18:54

If you have high volume website and still would like to have a full level (9) of compression, the best idea would be to put your static content on Amazon S3 or similar object storage services and upload the compressed files.

You still would want to use nginx to compress your HTML, so better to keep that value to normal, I use 5 there.

I would want to use your suggestion, but I currently haven't included a comp_level in my config, so I can't tell what level I'm currently at. Do you know what the defaults are? Source?
– Hassan BaigFeb 12 '18 at 17:09