Multiple site addresses with catch-all in one line

Hello,
i want to redirect everything to my first domain with a catch-all from the first and every sub domain of my second domain.

Forwarding with individual rules works fine, but as soon as it is written in only one line it doesn’t work.
Error 404… is not served on this interface

firstDomain.tld {
        root /var/www/firstDomain.tld
        gzip
}

secondDomain.tld, *.secondDomain.tld, *.firstDomain.tld {
        redir  https://firstDomain.tld/
}

Omiting the , or adding " does not help so far.
What am I missing or is it just not possible without regex?

To start with Caddy doesnt require , between host names just spaces

Could you give an example of the url you are calling that is failing and if possible response from curl?

Okay thanks, that solved my secondDomain.tld to firstDomain.tld, but the catch-all does not work on both domains.

root@try /etc/caddy # cat Caddyfile
firstDomain.tld {
        root /var/www/firstDomain.tld
        gzip

}

secondDomain.tld *.secondDomain.tld *.firstDomain.tld {
        redir  https://firstDomain.tld/
}
root@try /etc/caddy # curl -i firstDomain.tld
HTTP/1.1 301 Moved Permanently
Connection: close
Location: https://firstDomain.tld/
Server: Caddy
Date: Sun, 18 Feb 2018 11:08:13 GMT
Content-Length: 56
Content-Type: text/html; charset=utf-8

<a href="https://firstDomain.tld/">Moved Permanently</a>.

root@try /etc/caddy # curl -i secondDomain.tld
HTTP/1.1 301 Moved Permanently
Connection: close
Location: https://secondDomain.tld/
Server: Caddy
Date: Sun, 18 Feb 2018 11:08:17 GMT
Content-Length: 54
Content-Type: text/html; charset=utf-8

<a href="https://secondDomain.tld/">Moved Permanently</a>.

root@try /etc/caddy # curl -i www.firstDomain.tld
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Sun, 18 Feb 2018 11:08:23 GMT
Content-Length: 58

404 Site www.firstDomain.tld is not served on this interface
root@try /etc/caddy # curl -i www.secondDomain.tld
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Sun, 18 Feb 2018 11:08:27 GMT
Content-Length: 56

404 Site www.secondDomain.tld is not served on this interface

The commas aren’t the issue.

Remember that Caddy cannot enable automatic HTTPS for sites that have a wildcard in the hostname:

Caddy automatically enables HTTPS for all your sites, given that some reasonable criteria are met:

  • The host is not empty, not localhost, not a wildcard, and not an IP address

When you run Caddy, you will see in both the logs and the stdout that it is serving the wildcard names on the default port of 2015, because automatic HTTPS is not enabled. (Let’s Encrypt does not yet issue wildcard certificates. When it does, this will be a different story – but even then you’ll have to enable the DNS challenge.)

So for the wildcard hosts, you’ll have to do the HTTPS configuration more traditionally like other web servers:

https://*.firstdomain.tld, https://*.seconddomain.tld {
    tls ... # give your wilcard cert and key here
    redir https://firstdomain.tld/
}
http://*.firstdomain.tld, http://*.seconddomain.tld {
    redir https://firstdomain.tld/
}

Edit: Actually, you can still use automatic https for wildcard hosts, but you have to use on-demand TLS. This is documented on the automatic HTTPS page I linked to above.

4 Likes

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