Trying to reverse_proxy to many backends over a range of ports.
Is there any way to do this without manually typing out each port by hand? Is there a shorthand pattern feature I’m not aware of? Is there any possibility of this feature being added in the future?
Technically we have code in place to support port ranges, but we have a condition in place which rejects upstreams which use a port range:
if numPorts := addr.PortRangeSize(); numPorts != 1 {
return DialInfo{}, fmt.Errorf("upstream %s: dial address must represent precisely one socket: %s represents %d",
u.Dial, dial, numPorts)
}
I think the reason we did this is that it would require modifying in-place the config the user provided, so if you were to read back the config from the admin API, you would get a different config than what you gave it.
Like for example you’d run a config with ["localhost:5000-5001"] then run curl localhost:2019/config/ to get the config back from the admin API and you’d see in the config ["localhost:5000", "localhost:5001"].
The runtime code references the actual config, and uses it as reference for which upstreams to maintain state for (health status, failed request count, etc).
All that said, I don’t see any problem with making upstream ranges work in the Caddyfile (by expanding the range to multiple upstream addresses in the adapted JSON config), but it probably couldn’t work directly in JSON configs because of the above.