55 Nginx中添加gzip_static支持

55 Nginx中添加gzip_static支持

55.1 报错

[root@nginx-100 /usr/local/nginx/conf]# cat nginx_gzip.conf 
gzip off;          # 关闭gzip压缩功能
gzip_types *;      # 压缩源文件类型,根据具体的访问资源类型设定
gzip_comp_level 6; # gzip压缩级别
gzip_min_length 1024;   # 进行压缩响应页面的最小长度, content-length
gzip_buffers 4 16k;     # 缓存空间大小
gzip_http_version 1.1;  # 指定压缩响应所需要的最低HTTP请求版本
gzip_vary on;           # 往头信息中添加压缩标识
gzip_disable "MSIE [1-6]\.";  # 对IE6 以下的版本都不进行压缩
gzip_proxied off;             # nginx作为反向代理压缩服务端返回数据的条件
gzip_static on;    # 开启访问资源同名的 .gz 文件 
[root@nginx-100 /usr/local/nginx/conf]# nginx -t && nginx -s reload
nginx: [emerg] unknown directive "gzip_static" in /usr/local/nginx/conf/nginx_gzip.conf:10
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

55.2 添加模块

1.查看当前nginx的配置参数

[root@nginx-100 ~]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx \
--modules-path=/usr/local/nginx/modules --conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid --lock-path=/usr/local/nginx/logs/nginx.lock

2.将nginx应用程序中sbin目录下nginx二进制文件进行备份

[root@nginx-100 ~]# cd /usr/local/nginx/sbin/
[root@nginx-100 /usr/local/nginx/sbin]# mv nginx nginxold
[root@nginx-100 /usr/local/nginx/sbin]# ls -ltr
total 3736
-rwxr-xr-x 1 root root 3824976 Mar 12 23:40 nginxold

3.进入nginx安装目录

[root@nginx-100 ~]# cd /root/nginx/core/nginx-1.16.1/

4.执行 make clean 清空之前编译的内容

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# make clean
rm -rf Makefile objs

5.使用 configure 配置参数

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx --modules-path=/usr/local/nginx/modules \
--conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/logs/nginx.pid \
--lock-path=/usr/local/nginx/logs/nginx.lock --with-http_gzip_static_module

6.make 命令编译

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# make

7.拷贝编译后nginx二进制文件

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# cp objs/nginx /usr/local/nginx/sbin/

8.升级更新

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# make upgrade 
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

9.检查不再报错

[root@nginx-100 ~/nginx/core/nginx-1.16.1]# nginx -t && nginx -s reload
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

———————————————————————————————————————————————————————————————————————————

                                                                                                                         无敌小马爱学习

posted on 2026-05-15 17:09  马俊南  阅读(5)  评论(0)    收藏  举报