Closed Perlovka closed 6 years ago
@Perlovka It is not possible to implement because internal structure for hased upstream declared in ngx_http_upstream_hash_module.c. This is an internal feature of the hash upstream module. In custom upstream modules we have access only to ngx_http_upstream_rr_peer_t. But for hash nginx declare separate internal structure: typedef struct { / the round robin data must be first / ngx_http_upstream_rr_peer_data_t rrp; ngx_http_upstream_hash_srv_conf_t *conf; ngx_str_t key; ngx_uint_t tries; ngx_uint_t rehash; uint32_t hash; ngx_event_get_peer_pt get_rr_peer; } ngx_http_upstream_hash_peer_data_t;
We don't have access to this structure.
More: dynamicaly add/remove peers from hashed upstream corrupts the memory.
You may write custom balancer with lua-nginx-module by balancer_by_lua_block.
When upstream is defined with hash consistent, upstream server will be added via HTTP API, but will not receive traffic.
Example config: