Want to reverse proxy so many white label domains

1. Caddy version (caddy version):

v2.3

2. How I run Caddy:

caddy run --config=caddy.json

a. System environment:

Ubuntu 20.04

b. Command:

caddy run --config=caddy.json

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

{
	"apps": {
		"tls":{
            "automation":{
                    "policies":[{
                            "issuer":{
                                    "module": "acme",
                                    "challenges": {
                                            "dns": {
                                                "provider": {
                                                    "name": "cloudflare",
                                                    "api_token": "CLOUDFLARE_API_TOKEN"
                                                }
                                    }
                                }
                            }
                    }]
            }
    },
		"http": {
			"servers": {
				"example": {
					"listen": [":443"],
					"routes": [
						{
                    "match": [{"host": [
                                  "app.example.net"
                            ]}],
                    "handle": [
                            {
                            "handler": "reverse_proxy",
                            "upstreams": [
                                            {"dial":"x.x.x.x:4000"}]
                    }]
            },
						{
							"match": [{"host": [
									"*.example.net",
									"example1.co.li",
									"example2.co.li",
									"example3.com"
								]}],
							"handle": [
								{
								"handler": "reverse_proxy",
								"upstreams": [
										{"dial":"x.x.x.x:5000"}
                ]
							}]
						}
					]
				}
			}
		}
	}
}

3. The problem I’m having:

I want to server my clients domains from caddy, some of them are using subdomains and some of them are using white label domains.
Subdomains are working fine by adding wildcard record i.e. *.example.net .

But the problem is, right now I am adding each white label domain in my config file to make it work. Like this -

"match": [{"host": [
									"*.example.net",
									"example1.co.li",
									"example2.co.li",
									"example3.com"
								]}],

As per your documentation, it is possible to configure caddy to serve all the domain names you do not know and that can’t be configured ahead of time.
But I was enable to find how to do that.

4. Error messages and/or full log output:

When I try to access the new white label domain example4.co.li then I got “Secure Connection Failed” error.

5. What I already tried:

I tried to add “*” along with all the listed domains to support all the upcoming clients white label domains but it didn’t work.

6. Links to relevant resources:

Please upgrade to v2.4.5!

The On-Demand TLS section in the docs explains. What are you missing?

Is there any specific reason you’re using JSON config instead of Caddyfile? What you’re currently doing is easier to configure via the Caddyfile.

You can use the caddy adapt command to get the JSON config for a particular Caddyfile, great way to get started with JSON if you’re not sure what pieces are required in JSON.

Thanks for your reply.

ok…I will upgrade to the caddy 2.4.5

Sorry but I could not understand with the documentation how to configure it for all domains.
My question is that - Can I add * in the list of matched host to allow all the domains that we don’t know in advance? Like -

"match": [{"host": [                "*",
									"*.example.net",
									"example1.co.li",
									"example2.co.li",
									"example3.com"
								]}],

I am more comfortable in JSON format that is why I am using it.

@Rimjhim_Jain The docs for the host request matcher state that a * will match one domain label only, not an entire domain name.

Were the on-demand docs really not helpful for you? It even links to complete, working examples for on-demand TLS: Serving tens of thousands of domains over HTTPS with Caddy

I tried to go through the doc again and converted caddy json config to caddyfile and it is working now.
Thanks for your support!

2 Likes

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