Reputation: 493
I have an nginx + passenger installed on Amazon Linux EC2 server, running a Rails application. The application yields JSON responses.
The JSON response is rendered with length header:
# test_controller.rb
# result contains a large 400k JSON string
headers["Content-Length"] = result.size.to_s
render :json => result
I tried enabling gzip, but the response is still not compressed. I checked it with GIDZipTest.
# nginx.conf
gzip on;
gzip_http_version 1.1;
gzip_comp_level 1;
gzip_proxied any;
gzip_vary on;
gzip_min_length 500;
gzip_types application/x-javascript application/json;
Upvotes: 3
Views: 2829
Reputation: 21
gzip_types works! In my case, application/javascript also required for Ruby on Rails
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Upvotes: 1
Reputation: 493
Mystery solved. The php script is not reliable.
This is reliable:
wget --header="accept-encoding: gzip" URL
Gets the compressed version.
Testing with Chrome and Charles sniffer convinced me that everything worked fine.
Upvotes: 0
Reputation: 405
I have it working properly, try adding (text/javascript)
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Upvotes: 7