【问题标题】:nginx conf uwsgi_pass not respecting DNS TTLnginx conf uwsgi_pass 不考虑 DNS TTL
【发布时间】:2019-09-06 00:12:12
【问题描述】:

我正在使用 nginx 以及上游 uwsgi 应用程序。 uwsgi 应用程序使用 AWS Cloudmap 作为服务发现。

我遇到的问题是cloudmap对uwsgi主机使用DNS解析。 uwsgi 似乎解析并缓存了进入 uwsgi_pass 的所有内容。

例如在 uwsgi conf 我有uwsgi_pass uwsgi://web.sandbox:8000;

这意味着 nginx 服务器工作正常,直到 DNS 中的一个框被删除或换出。然后我收到一条错误消息,说 nginx 无法连接,因为它试图转到不存在的旧框。

No route to host) while connecting to upstream, client: 12.151.32.34, server: sandbox.mydomain.com, request: "GET /member/api/user/ HTTP/1.1", upstream: "uwsgi://172.30.1.89:8000"

我尝试使用resolver_timeout 0s;,但这似乎不影响 uwsgi_pass。

DNS TTL 设置为 10 秒,因此 nginx 不遵守该设置。

如何让 uwsgi_pass 尊重 TTL 或每次都解析域?

【问题讨论】:

    标签: nginx dns uwsgi aws-cloudmap


    【解决方案1】:

    我找到的解决方案是将以下内容添加到我的 nginx conf 的顶部

        # these two lines force DNS resolution (so if ip changes due to LB is replacement or if we use DNS service discovery)
        resolver ${DNS_SERVER};
        set $uwsgi_django_backend "${UWSGI_SERVER_FQDN}";
    

    将这两个变量替换为适合您环境的变量。

    现在您可以执行proxy_pass $uwsgi_django_backend;,它会重新评估 DNS。

    DNS 解析器通常只是 127.0.0.1,但有时您需要手动找到它(例如,如果您处于特殊的容器化环境中)

    export DNS_SERVER=$(cat /etc/resolv.conf |grep -i '^nameserver'|head -n1|cut -d ' ' -f2)
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2016-04-06
      • 2012-08-16
      • 1970-01-01
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 2015-10-13
      • 2020-08-23
      相关资源
      最近更新 更多