nginx - 如何在 nginx 负载均衡器的多个端口上添加健康检查?
问题描述
我们正在使用 nginx 来平衡我们的应用程序。有 4 个节点需要以循环方式进行负载平衡。负载平衡工作正常。
运行时服务正在侦听端口 9001 ,该端口在内部重定向到同一节点上的其他服务。
所以我们在 nginx.conf 中定义了上游,状态文件为“cluster.state”。以下是 nginx.conf 的摘录
upstream cluster {
zone cluster 64k;
state /var/nginx/state/cluster.state;
}
以下是“服务器”块中用于路由呼叫的摘录:
location /apipattern {
proxy_set_header Host $host:$server_port;
proxy_read_timeout 300s;
proxy_pass http://cluster/;
}
以下是 cluster.state 文件的摘录(更改了 FQDN,但端口正确)
server foobar1.com:9001 resolve;
server foobar2.com:9001 resolve;
server foobar3.com:9001 resolve;
server foobar4.com:9001 resolve;
要求是进行健康检查(对于 cluster.state 中提到的节点)。这些节点上的健康检查服务(2 个服务)在端口8081和8082上可用,uri=/healthcheck/isup(而不是在 9001 上)
我们如何配置这些健康检查?
解决方案
you can add multiple health_check directives under location directive with custom port and uri to have compound/multiple monitors for upstream. This is only possible with NGINX plus, which offers active health checking.
location /juice {
proxy_set_header Host $host;
proxy_pass http://juice/;
health_check port=800 uri=/custom.html;
health_check port=8081 uri=/hello.html;
}
推荐阅读
- c# - 使用 Serilog 将数据添加到 SQL Server 中的新列
- c++ - SHCreateDataObject/IDataObject 在 CDefView::OnBeginDrag 期间表现出奇怪的行为
- android - 在Android中向下滚动ListView时如何隐藏工具栏?(Xamarin)
- google-apps-script - 我的电子邮件是否被跟踪?我不断收到 Google Apps 脚本故障。下面的电子邮件,我跳过了多个错误
- reactjs - 如何在 ReactJS-PhpStorm 中使用“mobx”?谢谢
- html - 文字和图片并排
- css - 如何在移动设备上的 wordpress 主题上从滑动侧边栏中删除删除徽标
- facebook - Facebook Feed API 行为异常
- socket.io - 连接套接字服务器时出现“由于 xhr 轮询错误而导致的连接错误”
- mongoose - 如果给定参数,猫鼬聚合过滤器