resolver 10.0.0.1;
upstream dynamic {
zone upstream_dynamic 64k;
server backend1.example.com weight=5;
server backend2.example.com:8080 fail_timeout=5s slow_start=30s;
server 192.0.2.1 max_fails=3;
server backend3.example.com resolve;
server backend4.example.com service=http resolve;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server {
location / {
proxy_pass http://dynamic;
health_check;
}
}
这里的resolve需要商业版才支持,真是不OK
server {
listen 80;
server_name backend.example.com;
location / {
resolver 10.0.0.1 valid=30s ipv6=off;
resolver_timeout 10s;
set $dynamic "backend1.example.com";
proxy_pass http://$dynamic;
}
}
按上面的改可以解决proxy host backend1.example.com主机的的DNS解析IP变更问题