【问题标题】:nginx dynamic proxy_pass based on database lookup基于数据库查找的nginx动态proxy_pass
【发布时间】:2018-02-07 14:07:27
【问题描述】:

我有一个带有通配符子域的网站:*.mydomain 运行 nginx。 我想根据子域将 proxy_pass 传递到另一台服务器上的不同端口。

例如:
abc.mydomain -> proxy_pass http://otherdomain:10001
foo.mydomain -> proxy_pass http://otherdomain:10002
等等

要重定向到的端口在数据库中,我已经可以通过调用 url 来查找它:

卷曲http://mydomain/getport/abc -> 10001
卷曲http://mydomain/getport/foo -> 10002

我的网站上有数百个子域。如何在每次访问时进行这样的动态端口查找,以便在 nginx 中与 proxy_pass 一起使用?

我当前单个子域的 nginx 配置是这样的:

server {
    listen 80;
    server_name abc.mydomain;

    location / {
        proxy_pass http://otherdomain:10001;
    }
}

谢谢

【问题讨论】:

  • 我怀疑该解决方案与使用 Lua 脚本查询端口查找 url,然后在 proxy_pass 语句中使用结果有关。但是我不确定 Lua 是否熟悉,或者是否有更简单的替代方案。
  • 你最后解决了吗?

标签: nginx nginx-reverse-proxy


【解决方案1】:

发现这可能有助于解决问题。使用 OpenResty,将 URI 保存到 Redis,并查找每个请求 URI 架构。

https://openresty.org/en/dynamic-routing-based-on-redis.html

【讨论】:

    猜你喜欢
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 2021-07-10
    相关资源
    最近更新 更多