将管理 url 流量重定向到特定负载均衡器

Redirecting admin url traffic to a particular load balancer

当前设置: 我有两个负载均衡器,每个负载均衡器都包含来自不同区域的 EC2 实例。主区域有读写数据库,辅助区域有主数据库的只读副本。

Route 53 中还有 2 个记录集,它们配置了负载均衡器,这样每当用户访问我的网站时,流量就会在 70:30

中的这两个负载均衡器之间分配

为什么我选择只读?这样我只需要更新一个数据库,更改就会在所有从服务器之间同步。

问题: 当我用管理员 url 更新我的网站时,我有 30% 的机会连接到只读数据库,因此当数据库被锁定时我会收到服务器错误。

我在找什么: 是否有可能在有人访问 admin url、eg:www.example.com/admin 时将我的流量路由到读写数据库应该总是命中我的主服务器,以便任何写操作是仅在我的读写数据库中完成。

我正在使用带有 mysql 数据库的 Apache 服务器。

谢谢。

您可以为 Application Load Balancer 配置侦听器。我不想重写文档中的所有内容,但我认为这可以解决您的问题:

Benefits

Using an Application Load Balancer instead of a Classic Load Balancer has the following benefits:

Support for path-based routing. You can configure rules for your listener that forward requests based on the URL in the request. This enables you to structure your application as smaller services, and route requests to the correct service based on the content of the URL.

Here is the full documentation