Regex for matcher

Trying to get a specific regex for a general matcher…but I want it to exclude some certain strings, eg hass or unifi.
My initial base is:

This finds everything. To exclude and I managed to get the following to work in


But I’m trying to feed this to caddy, and it’s complaining it’s not valid perl (I’d have thought it was go). regex for go doesn’t see to have a negative lookahead.

What I’m wanting is in a Caddyfile to deal with a reverse proxy matcher, and only if not found to use the (.*) at the end. {
        @unifi host
        reverse_proxy @unifi {
            transport http {

    @allSubdomains header_regexp sub host (.*)\
    handle @allSubdomains {

       reverse_proxy {re.sub.1}

What seems to happen with this, is if I put it still gets to the @allSubDomains.

Next time, please fill out the help topic template, as per the forum rules. It’s important so we get full context for your question, to make sure we’re on the same page. Because of that, I need to make some assumptions, which may be incorrect.

I don’t understand. Please show the error message you got. Caddy definitely uses Go’s regexp engine, RE2: Syntax · google/re2 Wiki · GitHub

If all you need is to grab the part of a domain, you can use {labels.*} placeholders, i.e. {labels.2} for the subdomain (where the number is right-indexed, so 0 is com).

The reason that Caddyfile doesn’t work is because directives are sorted according to a predetermined order (see Caddyfile Directives — Caddy Documentation), where handle is higher than reverse_proxy, so your regexp one runs first. You can run caddy adapt --pretty --config /path/to/Caddyfile to see the JSON output which will show you exactly the order directives were sorted.

Please also see the reverse_proxy docs about proxying to HTTPS upstreams:

1 Like

Sorry, there was exception, I suspect related to go/perl (whatever caddy uses) not supporting a negative lookahead, can ignore this thread.

I’m still struggling with my concept of using caddy-docker-proxy which creates the c addy file dynamically, and dns. I just can’t get my head over having to put in entries for each service in dns and then have all the reverseproxy entries created automatically.

I have another thread I need to raise regarding env variables (for cloudflare key) not being loaded. So will fill in template for that.

This topic was automatically closed after 30 days. New replies are no longer allowed.