caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.48k stars 3.96k forks source link

Applying for Wildcard certificates for multiple subdomains #6027

Closed tareny closed 7 months ago

tareny commented 7 months ago

How should I set it up so that Caddy can apply for a generic domain certificate? I have a total of 41 website, and each update will trigger the Let's Encrypt restriction. However, all I need to do is apply for one wildcard domain (example, *. example) to fully cover 41 domains. I asked my friend and he recommended this to me, but I didn't understand it. https://caddyserver.com/docs/caddyfile/patterns#wildcard-certificates Could you please guide me on how to set up Wildcard certificates

{

    acme_ca https://acme-v02.api.letsencrypt.org/directory
    acme_dns cloudflare 12345678901234567890
    email admin@example.com
    key_type p384
}
example.com {
    handle /api/* {
        reverse_proxy 127.0.0.1:65535
    }
    handle {
        file_server browse {
            root /www/root
            hide .*
        }
        @hidden path */.*
        respond @hidden 403
    }
}
1.example.com {
    reverse_proxy 127.0.0.1:10001
}
.
.
.
40.example.com {
    reverse_proxy 127.0.0.1:10040
}
mholt commented 7 months ago

I've been thinking about ways to make this easier, but for now, this pattern is in our docs: https://caddyserver.com/docs/caddyfile/patterns#wildcard-certificates

Edit: oh, I see you've seen that already. What is unclear about it?

tareny commented 7 months ago

I've been thinking about ways to make this easier, but for now, this pattern is in our docs: https://caddyserver.com/docs/caddyfile/patterns#wildcard-certificates

Edit: oh, I see you've seen that already. What is unclear about it?

I didn't understand this doc. Can you help me modify my caddyfile so that he can apply for wildcard certificates @mholt

francislavoie commented 7 months ago

What don't you understand? We think it's pretty clear.

tareny commented 7 months ago

This is my configuration file. I want to configure a 404 page for 01.example.com, but setting it up like this will prevent Caddy2 from running properly

*.example.com {
    @01 host 00.example.com
    ......
    @40 host 40.example.com

    handle @00 {
        handle_errors {
            rewrite * /{err.status_code}.html
            file_server
        }
    root * /srv/root
    file_server
    }
    ......
    handle @40 {
        reverse_proxy 127.0.0.1:10040
    }
    handle {
        abort
    }
}
francislavoie commented 7 months ago

You can't put handle_errors inside a handle, it must be top level. But you may put handle inside handle_errors. If you simply flip those two lines, it should work.