- 系统环境:
[root@nginx01 ~]# cat /etc/redhat-release #==》系统版本 centos linux release 7.5.1804 (core) [root@nginx01 ~]# uname –r #==》内核版本 3.10.0-862.el7.x86_64 [root@nginx01 ~]# uname -m #==》系统架构 x86_64 [root@nginx01 ~]# echo $lang #==》系统字符集 en_us.utf-8 [root@nginx01 ~]# /application/nginx/sbin/nginx –v #==》nginx版本 nginx version: nginx/1.20.2
- 操作说明:
/opt/nginx-1.20.2 ### nginx 源码安装程序目录 /usr/local/nginx-1.20.2 ### nginx 安装目录 --with-http_gzip_static_module ### 本教程演示添加的nginx 内置模块
1、查看nginx已编辑的模块
[root@nginx01 ~]# nginx -v nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (red hat 4.8.5-44) (gcc) built with openssl 1.0.2k-fips 26 jan 2017 tls sni support enabled configure arguments: --prefix=/usr/local/nginx1.20.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
2、nginx官网查看内置模块
–with-http_gzip_static_module 是否默认安装
提示: nginx 官网地址: https://nginx.org/en/docs/configure.html ,从以下内容可以看出 内置模块 --with-http_gzip_static_module 不是默认安装
--with-http_gzip_static_module enables building the ngx_http_gzip_static_module module that enables sending precompressed files with the “.gz” filename extension instead of regular files. this module is not built by default.
3、停止nginx服务
nginx -s stop
4、nginx下载源码软件包
提示: 下载的nginx 源码软件包要与现在的nginx软件包版本一致
wget -p /opt/ https://nginx.org/download/nginx-1.20.2.tar.gz tar xf /opt/nginx-1.20.2.tar.gz -c /opt/
5、重新编辑已编辑的模块并添加新的模块
–with-http_gzip_static_module
注意:不要执行make install命令,否则会覆盖安装nginx(nginx配置文件会全部丢失)
cd /opt/nginx-1.20.2 ./configure --prefix=/usr/local/nginx1.20.2 --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_gzip_static_module make
6、备份原来nginx 二进制文件并替换新编辑的nginx二进制文件
mv /usr/local/nginx/sbin/nginx /tmp/ cp -rp /opt/nginx-1.20.2/objs/nginx /usr/local/nginx/sbin/
7、启动nginx服务并检查
nginx -t nginx [root@nginx01 ~]# nginx -v nginx version: nginx/1.20.2 built by gcc 4.8.5 20150623 (red hat 4.8.5-44) (gcc) built with openssl 1.0.2k-fips 26 jan 2017 tls sni support enabled configure arguments: --prefix=/usr/local/ngin
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论