In my current openresty deployment, I have an upstream_server.conf which contains 20+ upstream blocks. As we add a new endpoint(ELB), I have to manually update this configuration file and restart nginx. Upstream backend information is stored in the MySQL database along with service endpoint and other routing information.1. Can I achieve above without restarting nginx using balancer_by_lua? I can read the DB and get all domain/port/conn-pool size etc.
2. Do I need multiple upstream backend { } to match my current config? If yes, h How can I register multiple upstream backend { } sections dynamically?
3. Does balancer.set_current_peer(host, port) add the host/port to current upstream connection pool or just used for routing current request?
upstream foo.com {
server 0.0.0.1; # just an invalid address as a place holder
balancer_by_lua_file "/path/to/your/lua/file";
}
When new services are registers, I am storing the service Uris and ELB address in the database. Each ELB is configured using it's own upstream backend_elb_xxx {} block which is dynamically used in the proxy_pass section.
E.g. proxy_pass https://$upstream_backend_elb$upstream_uri
Both of these variables are populated based on the uri matching to upstream section from the database.
I want to add these upstream backend_elb_xxx {} sections without restart.