[英]gzip not working in nginx + passenger
I have an nginx + passenger installed on Amazon Linux EC2 server, running a Rails application. 我在Amazon Linux EC2服务器上安装了nginx +乘客,运行Rails应用程序。 The application yields JSON responses.
该应用程序产生JSON响应。
The JSON response is rendered with length header: JSON响应使用长度标头呈现:
# 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. 我尝试启用gzip,但响应仍未压缩。 I checked it with GIDZipTest .
我用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;
我有它正常工作,尝试添加(文本/ javascript)
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_types works! gzip_types有效! In my case, application/javascript also required for Ruby on Rails
就我而言,Ruby on Rails也需要application / javascript
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Mystery solved. 谜团已揭开。 The php script is not reliable.
php脚本不可靠。
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. 使用Chrome和Charles嗅探器进行测试使我确信一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.