Nginx无法gzip输出响应。 我已经使用chrome dev工具以及使用简单的curl命令确认了它。客户端(浏览器)正在发送" Accept-Encoding:gzip,deflate"在发出HTTP请求时。
这是nginx.conf文件
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_vary on;
gzip_comp_level 5;
gzip_types text/html application/x-javascript text/css application/javascript text/javascript text/plain text/xml application/json application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/xml font/eot font/opentype font/otf image/svg+xml image/vnd.microsoft.icon;
gzip_static on;
server {
listen 8080;
server_name localhost;
location / {
root /home/ubuntu/project1/src;
index app.html;
}
}
server {
listen 8081;
server_name localhost;
location / {
root /home/ubuntu/project2/src;
index app.html;
}
}
}
和mime.types文件
types {
text/html html htm shtml;
text/css css;
text/xml xml rss;
image/gif gif;
image/jpeg jpeg jpg;
application/x-javascript js;
text/plain txt;
text/x-component htc;
text/mathml mml;
image/png png;
image/x-icon ico;
image/x-jng jng;
image/vnd.wap.wbmp wbmp;
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/pdf pdf;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/zip zip;
application/octet-stream deb;
application/octet-stream bin exe dll;
application/octet-stream dmg;
application/octet-stream eot;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/mpeg mp3;
audio/x-realaudio ra;
video/mpeg mpeg mpg;
video/quicktime mov;
video/x-flv flv;
video/x-msvideo avi;
video/x-ms-wmv wmv;
video/x-ms-asf asx asf;
video/x-mng mng;
}
curl命令
curl http://myserver/templates.js --silent --write-out "%{size_download}\n" --output /dev/null
curl http://myserver/templates.js --silent -H "Accept-Encoding: gzip,deflate" -H “Accept: text/javascript” --write-out "%{size_download}\n" --output /dev/null
两个命令都返回相同的字节数(在本例中为17414)。
我可能无法分享template.js
答案 0 :(得分:0)
我尝试添加其他一些属性。当我在gzip_min_length 1000;
文件中添加以下内容时,它对我有用:
20
真奇怪的行为!根据文档,其默认值为{{1}}
{{3}}