For example, instead of:
:81 {
tls /etc/xxx/xxx.crt /etc/xxx/xxx.key
proxy / 127.0.0.1:8080 {
transparent
}
}
:82 {
tls /etc/xxx/xxx.crt /etc/xxx/xxx.key
proxy / 127.0.0.1:8080 {
transparent
}
}
...
:443 {
tls /etc/xxx/xxx.crt /etc/xxx/xxx.key
proxy / 127.0.0.1:8080 {
transparent
}
}
Can we do something like:
:81 - 443 {
tls /etc/xxx/xxx.crt /etc/xxx/xxx.key
proxy / 127.0.0.1:8080 {
transparent
}
}
OR even:
:81, :82, :83, ..., :443 {
tls /etc/xxx/xxx.crt /etc/xxx/xxx.key
proxy / 127.0.0.1:8080 {
transparent
}
}
I'm not spotting it in the docs (it would be here https://caddyserver.com/docs/caddyfile/concepts#addresses) but if I remember correctly, port ranges should be supported with a syntax like :81-443 (no spaces)
Caddy v2 does explicitly mention port ranges in the docs though https://caddyserver.com/docs/conventions
Using commas should also work to specify multiple labels. See https://caddyserver.com/v1/docs/caddyfile#labels
For next time, I recommend asking usage questions on https://caddy.community, this board is meant for bugs and feature requests.
@francislavoie I've tried :81-443 with caddy 1.x and there is an error parsing the config file. Are you sure this syntax is correct?
The error message I received:
โ caddy.service - Caddy HTTP/2 web server
Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-02-19 03:27:05 UTC; 10s ago
Docs: https://caddyserver.com/docs
Process: 19996 ExecStart=/usr/local/bin/caddy -log stdout -log-timestamps=false -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp (code=exited, stat
Main PID: 19996 (code=exited, status=1/FAILURE)
Feb 19 03:27:05 worker-96 systemd[1]: Started Caddy HTTP/2 web server.
Feb 19 03:27:05 worker-96 caddy[19996]: [INFO] Caddy version: v1.0.4
Feb 19 03:27:05 worker-96 caddy[19996]: error inspecting server blocks: parse //:81-443: invalid port ":81-443" after host
Feb 19 03:27:05 worker-96 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Feb 19 03:27:05 worker-96 systemd[1]: caddy.service: Failed with result 'exit-code'.
Are you sure this syntax is correct?
Like I said, no I wasn't certain, seems like it's not supported and I was misremembering.
For future reference to whoever comes by this, when re-reading the docs, I think the stuff in https://caddyserver.com/docs/conventions is meant for reverse_proxy addresses, not for site labels.
So yeah, I think your best option is listing every port as a label, either comma separated or not, as you've been answered here https://caddy.community/t/is-it-possible-to-listen-to-multiple-ports-in-caddy-1-x-with-the-same-setting/7045
@francislavoie The conventions page applies to all of Caddy's native configuration -- but config adapters can do whatever they please, and it just so happens that the Caddyfile parses addresses differently since addresses in the Caddyfile can be URLs with schemes and paths too. So port ranges do work in Caddy's native JSON config, it's just the Caddyfile that doesn't support them. I suppose they could but we'd have to find a way to make it work with Go's URL parser.