Nginx 安装 nginx_upstream_check_module 模块
nginx_upstream_check_module 与 Nginx 的关系图。我的 Nginx 是 1.23.1 版本,所以需要用 check_1.20.1+.patch 版本
进入你的 nginx 源码目录(有 configure 可执行文件的目录),我的在 /usr/local 目录下,将下载的 nginx_upstream_check_module-master.zip 放到 Nginx 源码目录。
cd /usr/local/nginx-1.23.1
// nginx_upstream_check_module-master.zip 包放到 /usr/local/nginx-1.23.1 目录中并解压
unzip nginx_upstream_check_module-master.zip
patch -p1 < nginx_upstream_check_module-master/check_1.20.1+.patch
/*
如果你的 Nginx 安装的时候也安装了 stream、stream_ssl_module、http_ssl_module 这三个模块,且只有这三个模块,那么下面这个命令无脑执行就行。除了 --prefix= 参数配置的路径可以按自己喜好修改,其他的就直接给我无脑粘贴执行。
如果你的 Nginx 不止安装了 stream、stream_ssl_module、http_ssl_module 这三个模块,那么你就继续加入你装的其他模块,你要不是加入那么你以前安装的模块都会被移除。
*/
./configure --prefix=/usr/local/nginx --with-stream --with-stream_ssl_module --with-http_ssl_module --add-module=nginx_upstream_check_module-master
// ===================> start 释义 <===================
--prefix:指定安装目录。
--with-stream:加入 stream 模块。
--with-stream_ssl_module:加入 stream 模块下的 ssl 子模块。
--with-http_ssl_module:加入 http 模块下的 ssl 子模块。
--add-module=nginx_upstream_check_module-master:安装 nginx_upstream_check_module-master 模块。
请注意,这里指定的是 /usr/local/nginx 作为安装目录。
// ===================> end 释义 <===================
// 编译及安装
make && make install
// 查看版本及配置
nginx -V
查看版本及配置效果图
/usr/local/nginx-1.23.1 是我 Nginx 源码目录,但我在编译安装过程中,使用 --prefix 参数将 Nginx 安装到了 /usr/local/nginx 目录。进入 /usr/local/nginx
cd /usr/local/nginx
// 编辑 nginx.conf 文件
vim /config/nginx.conf
// 在 http 块中配置加入配置
upstream cluster1 {
# simple round-robin
server 10.0.1.161:8086;
server 10.0.1.161:8087;
check interval=4000 rise=3 fall=5 timeout=3000 type=http;
}
// 在 http 块中 server 块下加入配置:
//这里 location /1 是什么鬼???别问,就单纯取个名字而已,随便你取什么名字 location /1 也好 location /cluster1 也好...
location /1 {
proxy_pass http://cluster1;
}
location /server_check {
check_status;
}
配置效果图
检查 Nginx 语法
nginx -t
启动 Nginx
cd /usr/local/nginx/sbin
./nginx
地址访问查看效果(Nginx 没有单独配置端口直接访问 ip/server_check,配置了端口的访问 ip:端口/server_check )