gzip not working on nginx for JSON responses

by Andrew Newby   Last Updated December 07, 2017 11:00 AM

I'm trying to figure out why my JSON responses are not being gzip'ed. In my main ngninx.conf, I have:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css text/html application/json  application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

Then in my script I a printing out the content type as:

print $IN->header( 'application/json' );

which converts to:

Content-Type: application/json \n\n

I see the correct content-type there, it's its not compressed:

curl -H "Accept-Encoding: gzip" -I 'https://www.example.com/cgi-bin/links/spots_load_new.cgi?catid=9&linkid=0&t=luna'
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Dec 2017 10:18:58 GMT
Content-Type: application/json
Connection: keep-alive
Keep-Alive: timeout=60
Access-Control-Allow-Origin: *

If I test it on a JS file, it works fine:

curl -H "Accept-Encoding: gzip" -I http://www.example.com/new_design/categories25.min.js
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Dec 2017 10:23:54 GMT
Content-Type: application/javascript
Last-Modified: Wed, 27 Sep 2017 14:21:09 GMT
Connection: keep-alive
Keep-Alive: timeout=60
Vary: Accept-Encoding
ETag: W/"59cbb3d5-323e"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Encoding: gzip

What am I missing? (I have rebooted nginx, FWIW :))

Tags : nginx gzip


Related Questions



Nginx Gzip Not Working

Updated December 03, 2016 08:00 AM

Turn off gzip for a location in Nginx

Updated November 30, 2015 22:00 PM

gzip compression not working with nginx and centos 7

Updated August 27, 2017 06:00 AM

Is it worth it to have gzip_static enabled with HTTP/2?

Updated September 19, 2017 14:00 PM