1
我想在我的nginx服務器上啓用gzip壓縮。該nginx.conf文件是在這裏:Nginx啓用gzip
http {
# Enable Gzip
server {
location ~* \.(?:ico|woff|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
location /api {
try_files $uri $uri/ /api/index.php;
}
location/{ ##merge
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
}
}
不幸的是,gzip壓縮不工作,谷歌的PageSpeed和Gtmetrix無法檢測到這一點。
我可以在哪裏放置gzip conf?
在http{}
server{}
或location{}
標記?
我已經嘗試過在http
,並在location
標籤太
謝謝@quito它的作品! – wpdaniel