Nginx重新编译添加新的模块

首先清楚自己要添加的模块,如http_realip_module,对应的编译参数为--with-http_realip_module
找到安装nginx的源码根目录,如果没有的话下载新的源码
查看ngixn版本及其编译参数

[root@xx-xx-nginx-xx-xx ]# ./nginx -V
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/soft/pcre-8.20 --with-pcre

进入nginx源码目录

cd nginx-1.x.x

以下是重新编译的代码和模块

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/soft/pcre-8.20 --with-pcre  --with-http_realip_module

ps:这里可以先复制-V查到的现有的模块,然后再追加自己要添加的模块
接下来有两种方式:
一、make && make install


直接覆盖安装,然后nginx -t&& nginx -s reload如果是提前对原有的nginx有了备份可以这样做,否则请参考方法二
方法二、make之后不执行make install


make完之后在objs目录下就多了个nginx文件,这个就是新版本的程序了

[root@xx-xx-nginx-xx-xx nginx-1.8.0]# ll objs/
total 5360
-rw-r--r-- 1 root root   12203 Jan 26 14:45 autoconf.err
-rw-r--r-- 1 root root   39190 Jan 26 14:45 Makefile
-rwxr-x--- 1 root root 5304067 Jan 26 14:46 nginx
-rw-r--r-- 1 root root    5253 Jan 26 14:46 nginx.8
-rw-r--r-- 1 root root    6588 Jan 26 14:45 ngx_auto_config.h
-rw-r--r-- 1 root root     657 Jan 26 14:45 ngx_auto_headers.h
-rw-r--r-- 1 root root    4104 Jan 26 14:45 ngx_modules.c
-rw-r----- 1 root root   80320 Jan 26 14:46 ngx_modules.o
drwxr-xr-x 8 root root    4096 Mar 22  2017 src

备份旧的nginx程序

cp /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak

把新的nginx程序覆盖旧的

cp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确

/usr/local/nginx/sbin/nginx -t

nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful

平滑重启nginx

/usr/local/nginx/sbin/nginx -s reload

查看ngixn版本极其编译参数

/usr/local/nginx/sbin/nginx -V

[root@xx-xx-nginx-xx-xx nginx-1.8.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/soft/pcre-8.20 --with-pcre --with-http_realip_module

这里多了我们要添加的http_realip_module模块

你可能感兴趣的:(Nginx重新编译添加新的模块)