nginx安装成功后,发现有一些其他模块没有编译进去,或者想额外添加一些模块,这时候就要重新编译nginx
下面以 --with-http_stub_status_module为例:
使用./nginx -V 查看没有该模块,使用下面方法添加:
进入nginx源码包(configure)此方法不适用于yum安装的nginx!
1 |
|
将要编译的参数重新添加到后面(之前的模块也要加上)
1 |
|
注意:这里只能make 千万别make install,否则就覆盖安装了
1 |
|
make完成后,在源码目录下会有一个objs目录,objs目录下就多了个nginx,这个就是新版本的程序了。
1 2 3 |
|
然后将objs目录下的nginx替换之前已经安装过的nginx。
先备份旧的nginx程序
1 |
|
把新的nginx程序覆盖旧的
1 |
|
如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”
建议使用如下语句cp
1 |
|
测试新的nginx程序是否正确
1 2 3 |
|
最后重启nginx
1 |
|
然后在nginx配置文件中server添加一个localtion
location /nginx-status { |
发现虽然nginx -t 不报错了但是还是无法使用该模块功能。报错可看ngixn日志就知道了。
解决办法:进行平滑更新一下nginx,避免重启带来业务影响。
1)查看nginx进程
[root@web01 conf.d]# ps -ef|grep nginx
root 10864 1 0 Jul01 ? 00:00:00 nginx: master process /app/nginx/sbin/nginx
nginx 18057 10864 0 12:25 ? 00:00:00 nginx: worker process
root 18246 15116 0 13:37 pts/1 00:00:00 grep --color=auto nginx
2)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程。
[root@web01 conf.d]# kill -USR2 10864
[root@web01 conf.d]# ps aux|grep nginx
root 10864 0.0 0.1 21256 1508 ? Ss Jul01 0:00 nginx: master process /app/nginx/sbin/nginx
nginx 18057 0.0 0.1 21256 1732 ? S 12:25 0:00 nginx: worker process
root 18259 0.1 0.3 45956 3240 ? S 13:38 0:00 nginx: master process /app/nginx/sbin/nginx
nginx 18260 0.0 0.1 46336 1904 ? S 13:38 0:00 nginx: worker process
root 18265 0.0 0.0 112704 960 pts/1 R+ 13:39 0:00 grep --color=auto nginx
3)向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程。
[root@web01 conf.d]# kill -WINCH 10864
[root@web01 conf.d]# ps aux|grep nginx
root 10864 0.0 0.1 21256 1508 ? Ss Jul01 0:00 nginx: master process /app/nginx/sbin/nginx
root 18259 0.0 0.3 45956 3240 ? S 13:38 0:00 nginx: master process /app/nginx/sbin/nginx
nginx 18260 0.0 0.1 46336 1904 ? S 13:38 0:00 nginx: worker process
root 18271 0.0 0.0 112704 960 pts/1 R+ 13:41 0:00 grep --color=auto nginx
4)发送QUIT信息,优雅的退出旧进程。
[root@web01 conf.d]# kill -QUIT 10864
[root@web01 conf.d]# ps aux|grep nginx
root 18259 0.0 0.3 45956 3240 ? S 13:38 0:00 nginx: master process /app/nginx/sbin/nginx
nginx 18260 0.0 0.1 46336 1904 ? S 13:38 0:00 nginx: worker process
root 18273 0.0 0.0 112704 960 pts/1 S+ 13:41 0:00 grep --color=auto nginx
然后更新nginx配置文件
nginx -s reload
再测试stub_status 模块
curl http://127.0.0.1:80/nginx-status