您的位置:首页 > 运维架构 > Nginx

Nginx添加新模块&平滑重启

2016-03-16 10:10 645 查看

需求

当编译完成后的Nginx需要添加新的模块时,我们需要添加该模块重新编译。

比如我这里的需求是:编译好Nginx后,我需要添加nginx-rtmp-module模块

环境

[系统环境:CentOS release 6.7 (Final) nginx/1.8.1]

nginx的安装位置:/opt/nginx

nginx软件包位置:/opt/software/nginx-1.8.1

准备

下载新模块

下载需要添加的模块:nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module.git[/code] 
放至指定位置:

mv nginx-rtmp-module /opt/software/nginx-1.8.1/modules


查看已编译的参数

/opt/nginx/sbin/nginx -V


configure arguments: --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/opt/software/pcre-8.35 --with-zlib=/opt/software/zlib-1.2.8 --with-openssl=/opt/software/openssl-1.0.1i


重新编译

带上新模块重新编译

使用上一步查询到的编译参数,带上–add-module=path_of_new_module

cd /opt/software/nginx-1.8.1


./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/opt/software/pcre-8.35 --with-zlib=/opt/software/zlib-1.2.8 --with-openssl=/opt/software/openssl-1.0.1i --add-module=/opt/software/nginx-1.8.1/modules/nginx-rtmp-module


make


注意:这里只有make,一定不要手贱顺手执行了make install,不然会覆盖安装的

平滑重启

上一步执行完成后,会在当前目录下生成objs目录,其中的nginx文件即为新的二进制文件

备份原文件

cp /opt/nginx/sbin/nginx /opt/nginx/sbin/nginx.bak


替换nginx二进制文件

cp -f /opt/software/nginx-1.8.1/objs/nginx /opt/nginx/sbin/nginx


正确性检查

/opt/nginx/sbin/nginx -t




reload Nginx

/opt/nginx/sbin/nginx -s reload


检查nginx进程是否启动

查看编译结果

/opt/nginx/sbin/nginx -V


Done!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: