gzip 压缩不适用于 nginx 和 centos 7

gzip compression not working with nginx and centos 7

我想使用 nginx 在我的虚拟主机上启用 gzip 压缩。我的控制面板是 Plesk17,但我可以访问服务器根目录。我在这个目录中找到了 vhost nginx 配置文件:

/etc/nginx/plesk.conf.d/vhosts

并在 server 块中添加此代码以启用 gzip:

gzip on;
gzip_disable msie6;
gzip_proxied any;
gzip_buffers 16 8k;
gzip_types    text/plain application/javascript application/x-javascript text/javascript text/xml text/css;
gzip_vary on;

重启 nginx 之后,当我检查 gzip 状态时,它看起来已禁用!

供您参考,我的配置文件顶部也有以下注释:

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

怎么了?如何启用 gzip?

要为特定域启用 gzip 压缩,打开 Domains > example.com > Apache & nginx Settings > Additional nginx directives 并向此部分添加指令。
如果你想在服务器范围内启用它,只需创建新文件 /etc/nginx/conf.d/gzip.conf 在其中添加内容并重新启动 nginx。