Mixed http https endpoints

1. Caddy version (caddy version):

Later / irrelevant

2. How I run Caddy:

I have not yet decided

a. System environment:

Debian 11

b. Command:

Paste command here.

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:

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
Make sure the backticks stay on their own lines.

3. The problem Iā€™m having:

Is it possible to have mixed http and https endpoints?


Is there some way to match only some endpoints?

http://example.com {
  match /api/thing1/a 
 match /api/thing1/c 
 // all other api endpoints over https

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Caddy will by default redirect all HTTP requests to HTTPS.

Are you asking that some URLs are served over HTTP while everything else redirects to HTTPS?

If so, yes, you can with request matchers, the handle directive, and the redir directive.

example.com {
	# Handling for HTTPS requests

http://example.com {
	@http-allowed /api/thing1/a* /api/thing1/c*
	handle @http-allowed {
		# handle it how you need

	# Redirect everything else to HTTPS
	handle {
		redir https://{hostport}{uri}
1 Like

Thank you. That is exactly what I was asking. How to make an HTTP block handle one set of endpoints and pass everything else off to HTTPS.

1 Like

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