大网数据广告活动
服务器运维问答

NGINX is not respecting DNS TTL of Upstream Server

· 52CE 我爱测

I have an NGINX TCP load balancer with the following configuration: user myusername; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; load_module /usr/lib/ngi…

问题原文

原帖链接 · A X · CC BY-SA 4.0

I have an NGINX TCP load balancer with the following configuration:

user myusername;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;
load_module /usr/lib/nginx/modules/ngx_stream_module.so;

events {
    worker_connections 1024;
}

stream {

    upstream api_backend_http {
        server myserver1.mydomain.com:80;
        server myserver2.mydomain.com:80;
    }

    upstream api_backend_https {
        server myserver1.mydomain.com:443;
        server myserver2.mydomain.com:443;
    }

    server {
        listen            80;
        proxy_pass        api_backend_http;
        proxy_buffer_size 16k;
        proxy_connect_timeout 1s;
    }

    server {
        listen            443;
        proxy_pass        api_backend_https;
        proxy_buffer_size 16k;
        proxy_connect_timeout 1s;
    }

    
}

The DNS TTL of myserver1.mydomain.com is set to 30 seconds. 45 Minutes after changing this, NGINX is still sending traffic to the old IP address.

This shouldn't happen - ideally it should respect the TTL of the upstream server DNS name. But it doesn't seem to be doing that. Does anyone know what the actual TTL is, and how to change it?

Side note, this feels like a bug in NGINX.

已采纳解答

原帖链接 · A X · CC BY-SA 4.0

After spending time on this, it seems that you basically have to buy NGINX Plus if you want this and also want to have multiple upstreams.

So consider looking at Envoy. It is free with a great license, and has both DNS refresh and upstream healthchecks built in.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-07-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。