Nginx – Will nginx route no traffic to an upstream host with weight 0

nginx

I would like to temporarily route no traffic to a host in an nginx upstream. Rather than commenting it out, as this means nginx would be completely programmatically unaware of it, I was wondering whether setting its weight to zero would have the same effect (routing no traffic to the host). This is unclear from the documentation here http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream

Will nginx honor weight=0?

Best Answer

From a (fairly cursory) reading of ngx_http_upstream_get_peer it seems nginx will pick a weight=0 server if there is nothing else to pick at all.

Specifically see https://github.com/nginx/nginx/blob/3fae83a91c6e5cda012adf6ee2783273e747f613/src/http/ngx_http_upstream_round_robin.c#L558

Related Topic