Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created December 2, 2024 07:46
Show Gist options
  • Select an option

  • Save wilmoore/ed318c2124d4d924d8031f6dbf4eac5d to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/ed318c2124d4d924d8031f6dbf4eac5d to your computer and use it in GitHub Desktop.
Software Engineering :: Web :: Development :: HTTP :: Server :: Caddy :: Configuration :: Caddyfile :: Example :: Wildcard certificates

Software Engineering :: Web :: Development :: HTTP :: Server :: Caddy :: Configuration :: Caddyfile :: Example :: Wildcard certificates

⪼ Made with 💜 by Polyglot.

If you need to serve multiple subdomains with the same wildcard certificate, the best way to handle them is with a Caddyfile like this, making use of the handle directive and host matchers:

You must enable the ACME DNS challenge to have Caddy automatically manage wildcard certificates.
*.example.com {
	tls {
		dns <provider_name> [<params...>]
	}

	@foo host foo.example.com
	handle @foo {
		respond "Foo!"
	}

	@bar host bar.example.com
	handle @bar {
		respond "Bar!"
	}

	# Fallback for otherwise unhandled domains
	handle {
		abort
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment