Map for wildcard domain

Hi,
I have a running caddy1 installation that I want to replace with caddy2.
I run my caddy1 with the parameter wildcard, so I only have one cert *.x.y.z.

I try to modify your setup but instead of phpmyadmin I would like to select authentication.
I can start caddy, but I only got empty files. I tried both:

  • v2.4.0-beta.1.0.20210330214204-e68dbe9cf8cf h1:vvo1zjA0E5CQgkxKlULvdE5VixBhf0YaORfvnLYePKk=
    and
  • v2.4.0-beta.1 h1:Ed/tIaN3p6z8M3pEiXWJL/T8JmCqV62FrSJCHKquW/I=
    but still only got empty responses and a similar error message as about:

“dial http:: unknown network http:”

Any ideas, how to fix this, or should I open a new thread?

My simplified Caddyfile:

(tlsdns) {
  tls certs@X.X.X {
    dns lego_deprecated rfc2136
  }
}

(authproxy) {
 basicauth {
    XXX  YYYY
  }
}

(logging) {
  log {
    format json
    output file /var/log/caddy2/caddy.log {
      roll_keep 7
    }
  }
}


*.x.y.z {
  encode gzip
  import tlsdns
  import logging

  map {labels.3} {backend} {auth} {
    # use http not https
    Host1    http://internal-name:9000 no
    Host2    http://10.0.0.1:9000 yes

  }
  @auth expression `{auth} == "yes"`
  handle @auth {
    import authproxy
  }

  reverse_proxy {backend}
}

I moved your comment into a new topic - it was already long, so best to ask this in its own topic.

In particular, your problem if that you included http:// in the map value. When using a placeholder for the value, it should just be a host and port. So remove http:// from your map.

1 Like

Thanks for the help. I should have seen that my self.

Now it is working. But I have another thing. I need to add and remove some header on some of the sites. I could extend it like I did with auth. But I only need this settings on 1 of the about 20 sites. Is there a better way to do it then have a map with 5 or 6 rows?
I saw this example in Matts post:

@customer2 host customer2.example.com
reverse_proxy @customer2 10.0.0.2:9000

But can I put a braket around that and specify other settings as well?

At that point I would just recommend using handle blocks for each site instead of using map.

@foo host foo.example.com
handle @foo {
	header {
		...
	}
	reverse_proxy ...
}

@bar host bar.example.com
handle @bar {
	header {
		...
	}
	reverse_proxy ...
}

handle {
    # Fallback for otherwise unmatched requests
}
1 Like

Cool. Thanks. That is what I tried to do, but my brakets where wrong and then I tried the map first :wink:
Many Thanks.

1 Like

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