Nginx 配置静态压缩(ngx_http_gzip_static_module)

Nginx提供静态压缩功能,对于比较大的文件,可以自动默认查找.gz后缀的压缩包。减小项目工程的大小。

  1. 第一,需要确定,nginx是不是已经配置了相关模块

nginx -V

  1. 找到当前nginx的配置位置, 先找到nginx从哪里运行起来的

ps -ef|grep nginx

  1. 根据运行路径,执行-t测试一下配置文件

/www/server/nginx/sbin/nginx -t

nginx: the configuration file /www/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /www/server/nginx/conf/nginx.conf test is successful

  1. 在nginx.conf文件内,对gzip进行配置

gzip_static on;
gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "msie6";
gzip_vary on;
#找不到预压缩文件,进行动态压缩
gzip  on;
gzip_min_length 100;
gzip_buffers 4 6k;
gzip_comp_level 5;
gzip_types application/javascript text/xml text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;    

gzip_vary on

对于支持gzip的请求反向代理缓存服务器将返回gzip内容,不支持gzip的客户端返回原始内容。

  1. 在执行一下配置测试,确定OK了再重启

/www/server/nginx/sbin/nginx -t

重启nginx

service nginx restart

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
繁繁_leon的头像 - 鹿快
评论 抢沙发

请登录后发表评论

    暂无评论内容