6

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 :))

UPDATE: Just to make it as simple as possible - I have created a test.json file (valid contents), and it still comes back as non-gzipped:

curl -H "Accept-Encoding: gzip" -I https://www.example.com/new_design/test.json
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 07 Dec 2017 17:58:25 GMT
Content-Type: application/json
Content-Length: 245
Last-Modified: Thu, 07 Dec 2017 17:55:58 GMT
Connection: keep-alive
Keep-Alive: timeout=60
ETag: "5a2980ae-f5"
Accept-Ranges: bytes
Andrew Newby
  • 1,041
  • 1
  • 22
  • 48

1 Answers1

7

Ah man - I can't believe how dumb this is!!!

The data in question was 245 bytes:

Content-Length: 245

...and I had this set:

gzip_min_length 256k set. I've changed it to:

gzip_min_length 128;

and it works fine now. ARGH!

Andrew Newby
  • 1,041
  • 1
  • 22
  • 48