Is it possible to listen to multiple ports in Caddy 1.x with the same setting?

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’ve tried :81-443 with caddy 1.x and there is an error parsing the config file.

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'.

Hi @aeroxy, yeah, you absolutely can!

Check this out: https://caddyserver.com/v1/docs/caddyfile#labels

As each token is parsed individually as a site address, you just list them out.

You were on the money with this one:

Using commas isn’t absolutely necessary unless you want to put newlines in your list of labels for a site. That said, I like to comma after every label, just an aesthetic preference.

Ranges won’t work, though. There’s no logic in the Caddyfile parser to turn a port range into a series of labels.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.