nginx

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > nginx > Nginx添加内置模块

Nginx添加内置模块过程

作者:大新屋

文章指导如何检查并添加Nginx的with-http_gzip_static模块:确认该模块未默认安装后,需下载同版本源码重新编译,备份替换原有二进制文件,最后重启服务验证功能
[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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文