nginx-upsync-module是微博开源的一个基于Nginx实现动态配置的模块,通过拉取Consul或 etcd(及其它)的上游数据,实现无需重新加载Nginx,动态修改后端服务器属性(weight,max_fails,down...)。
修改配置文件并重新启动Nginx可能并不总是很方便。例如,当遇到大流量和高负载,重启Nginx并在此时重新加载配置会进一步增加系统负载,并可能暂时降低性能。使用nginx-upsync-module模块则可以在不影响性能的情况下,更加平滑的扩展和收缩。
nginx-consul:
http { upstream test { upsync 127.0.0.1:8500/v1/kv/upstreams/test/ upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf; include /usr/local/nginx/conf/servers/servers_test.conf; } upstream bar { server 127.0.0.1:8090 weight=1 fail_timeout=10 max_fails=3; } server { listen 8080; location = /proxy_test { proxy_pass https://test; } location = /bar { proxy_pass https://bar; } location = /upstream_show { upstream_show; } }}nginx-etcd:
http { upstream test { upsync 127.0.0.1:2379/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off; upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf; include /usr/local/nginx/conf/servers/servers_test.conf; } upstream bar { server 127.0.0.1:8090 weight=1 fail_timeout=10 max_fails=3; } server { listen 8080; location = /proxy_test { proxy_pass https://test; } location = /bar { proxy_pass https://bar; } location = /upstream_show { upstream_show; } }}
评论