#第三方模块需要先进行下载,然后再编译时指定文件目录
1.查看当前编译模块
root@nginx sbin]# ./nginx -V #查看当前添加模块 nginx version: nginx/1.14.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --prefix=/nginx/ --add-module=/usr/local/src/nginx-1.14.2/echo-nginx-module-master [root@nginx sbin]#
2.查看需要添加的模块
#本次添加的模块 ngx_stream_core_module 属于属于nginx 官方模块不需要下载,第三方模块需要下载解压
[root@nginx stream]# pwd /usr/local/src/nginx-1.14.2/src/stream [root@nginx stream]# ls ngx_stream_access_module.c ngx_stream_split_clients_module.c ngx_stream.c ngx_stream_ssl_module.c ngx_stream_core_module.c ngx_stream_ssl_module.h ngx_stream_geoip_module.c ngx_stream_ssl_preread_module.c ngx_stream_geo_module.c ngx_stream_upstream.c ngx_stream.h ngx_stream_upstream.h ngx_stream_handler.c ngx_stream_upstream_hash_module.c ngx_stream_limit_conn_module.c ngx_stream_upstream_least_conn_module.c ngx_stream_log_module.c ngx_stream_upstream_round_robin.c ngx_stream_map_module.c ngx_stream_upstream_round_robin.h ngx_stream_proxy_module.c ngx_stream_upstream_zone_module.c ngx_stream_realip_module.c ngx_stream_variables.c ngx_stream_return_module.c ngx_stream_variables.h ngx_stream_script.c ngx_stream_write_filter_module.c ngx_stream_script.h [root@nginx stream]#
3.添加 stream 模块进行重新编译
root@nginx sbin]# ./nginx -V nginx version: nginx/1.14.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --prefix=/nginx/ --add-module=/usr/local/src/nginx-1.14.2/echo-nginx-module-master [root@nginx sbin]#
[root@nginx sbin]# cd /usr/local/src/nginx-1.14.2
[root@nginx nginx-1.14.2]# ls
auto CHANGES.ru configure echo-nginx-module-master html Makefile objs src
CHANGES conf contrib echo-nginx-module-master.zip LICENSE man README
#配置时需要将原先添加模块重新添加一遍
[root@nginx nginx-1.14.2]# ./configure --prefix=/nginx/ --add-module=/usr/local/src/nginx-1.14.2/echo-nginx-module-master --with-stream
4. 进行make操作
此处nginx源码目录为:/usr/local/src/nginx-1.14.2,即为编译命令执行目录。 make 此处一定不能使用make install命令,执行该命令会将原有nginx目录进行覆盖。
5. 停止nginx 服务,替换新的nginx 程序启动文件
[root@nginx nginx-1.14.2]# cd /nginx/sbin/ #进入nginx 启动目录 [root@nginx sbin]# ls nginx [root@nginx sbin]# ./nginx -s stop #停止服务 nginx: [emerg] unknown directive "stream" in /nginx//conf/nginx.conf:51
[root@nginx sbin]# cp nginx nginx-no-stream #备份nginx 启动文件
[root@nginx sbin]# ls
nginx nginx-no-stream
[root@nginx sbin]# cp /usr/local/src/nginx-1.14.2/objs/nginx ./nginx #替换原有nginx 程序文件
cp: overwrite ‘./nginx’? y
[root@nginx sbin]#
root@nginx conf]# cd ../sbin
[root@nginx sbin]# ls
nginx nginx-no-stream
[root@nginx sbin]# ./nginx-no-stream -t #nginx --t 检查添加了 stream 字段的配置文件,原有文件报错
nginx: [emerg] unknown directive "stream" in /nginx//conf/nginx.conf:15
nginx: configuration file /nginx//conf/nginx.conf test failed
[root@nginx sbin]# ./nginx -t #nginx -t 检查添加了stream 字段的配置文件, 检查通过
nginx: the configuration file /nginx//conf/nginx.conf syntax is ok
nginx: configuration file /nginx//conf/nginx.conf test is successful
[root@nginx sbin]# ./nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/nginx/ --add-module=/usr/local/src/nginx-1.14.2/echo-nginx-module-master --with-stream
[root@nginx sbin]#