[NGINX]宝塔面板对NGINX 添加 Nginx http upstream check 模块
有一些api接口,不确定是否一直为正常可以用的时候,使用第三方模块来进行健康状态检查
首先,理解几条命令,有助于编译过程中的问题
1: nginx -V 注意 是大写
这条命令可以查看到nginx的编译信息,方便编译nginx模块
2:./configure
这个命令是用于输入编译选项
3:make
这个命令适用于编译程序
其次,理解一下 宝塔面板的nginx安装位置 一般安装在 /www/server/nginx 中
接下来,让我们一起开始编译这个模块
首先 在终端中
git clone https://github.com/yaoweibin/nginx_upstream_check_module
cd nginx_upstream_check_module
pwd
记录解压的文件地址
切换到 nginx安装目录 进行patch 补丁,注意 patch补丁应该选择对应版本的
输入
patch -p1 < [刚刚pwd的路径]/check.patch
例如
patch -p1 < /root/nginxmodule/nginx_upstream_check_module/check.patch
然后运行 nginx -V 获得编译命令
例如
./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc
我们在上面的最后添加 --add-module= /root/nginxmodule/nginx_upstream_check_module/
变成
./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --add-module= /root/nginxmodule/nginx_upstream_check_module/
配置成功后输入
make 进行编译文件
然后备份
备份 cp /www/server/nginx/sbin/nginx /www/server/nginx/sbin/nginx.bak
替换文件安装
cp /www/server/nginx/src/objs/nginx /www/server/nginx/sbin/
此时,nginx已经支持 新加的模块了。
输入nginx -V
若编译命令与我们编译时的命令一致,说明安装成功
接下来配置 负载均衡的健康检查 即可
在nginx.conf中添加
upstream testserv {
server 127.0.0.1:8080;
server 127.0.0.1:8083;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "GET /zzbNew/url.jsp HTTP/1.0\r\n\r\n";
}
然后新建一个站点
开启反向代理
输入 http://testserv ; 作为反向代理的路径即可
编辑配置文件
添加一个路径
location /status {
check_status;
access_log off;
}
就可以使用 http://test.com/status 查看具体运行状况了