有没有办法动态配置nginx(或其他快速反向代理)? [英] Is there any way to configure nginx (or other quick reverse proxy) dynamically?

查看:51
本文介绍了有没有办法动态配置nginx(或其他快速反向代理)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有几个相同的节点,它们是某个 n 层服务的应用服务器.假设我们使用 Apache ZooKeeper 来保存分布式应用程序的所有配置.此外,我们有一个 nginx 作为负载平衡器和在此应用程序前面的反向代理.

Suppose we have several identical nodes which are the application servers of some n-tier service. And suppose we use Apache ZooKeeper to keep all the config's of our distributed application. Plus we have an nginx as a load balancer and reverse proxy in front of this application.

假设我们执行一个命令,该命令仅更改节点 1 上的数据,并且在一段时间内节点 2 与节点 1 不同.我们希望代理将所有特殊请求(需要特定数据)重定向到节点 1,直到所有信息都迁移到节点 2 并且节点 2 具有与节点 1 相同的数据.

So let's say we perform a command which changes data only on node1, and for some period of time node2 differs from node1. And we want proxy to redirect all that special requests (which need that specific data) to node1 until all the infomation has migrated to node2 and node2 has the same data as node1.

有什么方法可以让 nginx(或其他代理)从 Apache ZooKeeper 读取其配置?或者更广泛:有什么方法可以有效地动态切换代理配置?当然,它应该在没有(或最少)整个系统停机的情况下完成 - 因此重新启动 nginx 不是选项.

Is there any way to make nginx (or other proxy) read its config from Apache ZooKeeper? Or more broader: is there any way to effectively switch proxy configuration on fly? And of course it should be done without (or with minimal) downtime of the whole system - so restarting nginx is not the option.

推荐答案

Nginx 有两种修改配置的方法:

Nginx has two methods of changing configuration:

  • HUP 主进程的信号导致重新加载".Nginx 启动了一堆新的 worker,让旧的 worker 优雅地关闭,即他们完成现有的请求.没有服务中断.这种更改配置的方法非常轻量级和快速,但几乎没有限制:您不能更改缓存区域或重新编译 Perl 脚本.

  • HUP signal to the master process results in "reload". Nginx starts a bunch of new workers and lets the old workers to shutdown gracefully, i.e. they finish existing requests. There is no interruption of service. This method of configuration change is very lightweight and quick, but has few limitations: you cannot change cache zones or re-compile Perl scripts.

USR2 信号,然后 WINCH 然后 QUIT 到主进程导致可执行升级",这个序列让完全重新读取整个配置,甚至升级 Nginx 可执行文件.它还会重新加载磁盘缓存(这可能很耗时).这种方法也不会中断服务.

USR2 signal, then WINCH and then QUIT to the master process result in "executable upgrade" and this sequence lets completely re-read whole configuration and even upgrade the Nginx executable. It reloads disk caches as well (which maybe time consuming). This method results in no interruption of service too.

官方文档

这篇关于有没有办法动态配置nginx(或其他快速反向代理)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆