If Else Handler Matching

1. Caddy version (caddy version):


2. How I run Caddy:

Directly on debian buster amd64

a. System environment:

Debian Buster amd64

b. Command:

caddy run

d. My complete Caddyfile or JSON config:

*.website.org {
	tls {
		dns cloudflare {$CLOUDFLARE_API_KEY}

	@sub1 {
host sub1.website.org 

	handle @sub1 {

	@sub2 host sub2.website.org
	handle @sub2 {

3. The problem I’m having:

I want to create an else statement for requests that dont match the sub1 matcher, this should respond with a 403 error. I am not sure the handler syntax I need for this.

5. What I already tried:

I have tried experimenting with the ‘not’ keyword but I want to know if there is a more concise way to go about it.

Could you be more specific about what you want to happen? Are you trying to make anything that doesn’t match your sub1 matcher get proxied to port 8000, i.e. what you have for sub2 currently? Or are you looking to add a third handler to do something else?

The not matcher is likely what you want, but I don’t have a good picture of what exactly you want so I can’t give a precise answer.

Hi! Yes, I am trying to have one IP ( be able to access sub1.website.org and have access to the service running on port 9000. However I want other users (anyone not to receive a 403 Error. I have experimented with the respond 403 directive but I am not sure if I need to create 2 matchers to handle this.

You could just do this:

@blocked {
	host sub1.website.org
	not remote_ip
respond @blocked "Access Denied" 403

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