Nginx 配置静态压缩(ngx_http_gzip_stati
2021-03-27 本文已影响0人
紫云Miyula
Nginx提供静态压缩功能,对于比较大的文件,可以自动默认查找.gz后缀的压缩包。减小项目工程的大小。
- 首先,需要确定,nginx是不是已经配置了相关模块
nginx -V
- 找到当前nginx的配置位置, 先找到nginx从哪里运行起来的
ps -ef|grep nginx
- 根据运行路径,执行-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
- 在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的客户端返回原始内容。
- 在执行一下配置测试,确定OK了再重启
/www/server/nginx/sbin/nginx -t
重启nginx
service nginx restart