如何在nginx OSS上动态重配置上游服务器?
How can I dynamically reconfigure upstream servers on nginx OSS?
我有多个来自 nginx 负载均衡器的上游服务器:
upstream app {
# Make each client IP address stick to the same server
# See http://nginx.org/en/docs/http/load_balancing.html
ip_hash;
# Use IP addresses: see recommendation at https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
server 1.1.1.1:6666; # app-server-a
server 2.2.2.2:6666; # app-server-a
}
现在我通过关闭每台服务器(例如 systemctl myapp stop
)然后让 nginx 检测服务器已关闭来使用 active/passove 配置中的服务器。
但是我希望能够动态地更改上游服务器,而不必关闭应用程序服务器或 nginx OSS。我知道 proprietary upstream_conf
module 用于 nginx Plus,但我正在使用 nginx OSS。
如何在nginx OSS上动态动态重配置上游服务器?
您可以使用:
openresty 具有 lua 脚本能力的 OSS nginx 包
nginx with lua脚本(你可以使用nginx OSS和luajit自行配置)来实现这个。
dynx 可以实现您正在寻找的东西,它仍在进行中,但动态上游功能已经存在,并且可以通过休息进行配置 API.
我正在添加有关如何部署和配置 dynx 的详细信息:
- 你需要 docker 预热和 运行(用于测试目的
你可以有一个 1 swarm 机器),按照 docker documentation 来做。
在你需要部署堆栈之后,例如,使用这个命令(你需要在 dynx git root 上):
docker stack deploy -c docker-compose.yml dynx
要检查应用程序是否正确部署,您可以使用此命令:
docker stack services dynx
要配置可以通过 api 使用的位置,您可以执行以下操作:
curl -v "http://localhost:8888/configure?location=/httpbin&upstream=http://www.httpbin.org/anything&ttl=10"
测试是否有效:
curl -v http://localhost:8666/httpbin
如果您无法正常工作,请随时与我联系或在 github 上提出问题
我有多个来自 nginx 负载均衡器的上游服务器:
upstream app {
# Make each client IP address stick to the same server
# See http://nginx.org/en/docs/http/load_balancing.html
ip_hash;
# Use IP addresses: see recommendation at https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
server 1.1.1.1:6666; # app-server-a
server 2.2.2.2:6666; # app-server-a
}
现在我通过关闭每台服务器(例如 systemctl myapp stop
)然后让 nginx 检测服务器已关闭来使用 active/passove 配置中的服务器。
但是我希望能够动态地更改上游服务器,而不必关闭应用程序服务器或 nginx OSS。我知道 proprietary upstream_conf
module 用于 nginx Plus,但我正在使用 nginx OSS。
如何在nginx OSS上动态动态重配置上游服务器?
您可以使用:
openresty 具有 lua 脚本能力的 OSS nginx 包
nginx with lua脚本(你可以使用nginx OSS和luajit自行配置)来实现这个。
dynx 可以实现您正在寻找的东西,它仍在进行中,但动态上游功能已经存在,并且可以通过休息进行配置 API.
我正在添加有关如何部署和配置 dynx 的详细信息:
- 你需要 docker 预热和 运行(用于测试目的 你可以有一个 1 swarm 机器),按照 docker documentation 来做。
在你需要部署堆栈之后,例如,使用这个命令(你需要在 dynx git root 上):
docker stack deploy -c docker-compose.yml dynx
要检查应用程序是否正确部署,您可以使用此命令:
docker stack services dynx
要配置可以通过 api 使用的位置,您可以执行以下操作:
curl -v "http://localhost:8888/configure?location=/httpbin&upstream=http://www.httpbin.org/anything&ttl=10"
测试是否有效:
curl -v http://localhost:8666/httpbin
如果您无法正常工作,请随时与我联系或在 github 上提出问题