How to allow caddy to work with two subdomain and mercure

1. Caddy version (v2.4.0):

I’m trying to run caddy with two subdomain in a single caddy file. But i keep end up getting error while starting the caddy. So please help me out to sort this issue, Just help me to correct me this caddy file format, what am i doing wrong in here.

caddyt.domain.com {
root * /www/wwwroot/caddytest
php_fastcgi unix//run/php/php8.0-fpm.sock
file_server
tls admin@domain.com {
protocols tls1.2 tls1.3
}
}
test.caddyt.domain.com {
file_server
log {
output stderr
format json
}
route {
mercure {
transport_url local://local
publisher_jwt jwt-codegoesinhere-blahblahblah
subscriber_jwt jwt-codegoesinhere-blahblahblah
publish_origins *
cors_origins https://caddyt.domain.com
anonymous
subscriptions
{$MERCURE_EXTRA_DIRECTIVES}
}
respond /healthz 200
respond “Not Found” 404
}
}

2. Error Occurred

 run: adapting config using caddyfile: /etc/caddy/Caddyfile:10: unrecognized directive: test.caddyt.tamilchatz.com

Can’t start the CADDY service at all.

What’s the error?

Please fully complete the help topic template as it requests. We can’t help otherwise.

Its updated now with the error. Looks like the caddy file format is not right, or something else. Not sure what is issue in here.

Please use ``` before and after your config when pasting it, to preserve whitespace and formatting. The help topic template prompts you to do this.

Make sure you having closing braces for every opening brace.

Sorry, i did not get the part “Please use ``` before and after your config when pasting it,”

Could you show me an example from my code above?

Done thanks for the help, updated the config code in the post. At first i thought you are helping me to add those code in caddy file. Anyway, waiting for right answer to get my issue sorted.

This is the answer.

You should use tabs/spaces to indent your config, otherwise it becomes nearly impossible to see where the braces should go. Just like any programming language.

caddyt.domain.com {
   root * /www/wwwroot/caddytest
   php_fastcgi unix//run/php/php8.0-fpm.sock
   file_server
   tls admin@domain.com {
   	protocols tls1.2 tls1.3
   		}
   }
test.caddyt.domain.com {
	file_server
	log {
		output stderr
		format json
		}
	route {
		mercure {
		transport_url local://local
		publisher_jwt jwt-codegoesinhere-blahblahblah
		subscriber_jwt jwt-codegoesinhere-blahblahblah
		publish_origins *
		cors_origins https://caddyt.domain.com
		anonymous
		subscriptions{
			$MERCURE_EXTRA_DIRECTIVES
				}
		}
		respond /healthz 200
		respond “Not Found” 404
	}
}

OK i have updated the code and added the right braces. Now i get another error.

run: adapting config using caddyfile: parsing caddyfile tokens for 'route': /etc/caddy/Caddyfile:26 - Error during parsing: unrecognized directive: mercure

The mercure directive comes from a module that is NON-standard, see: Modules - Caddy Documentation

You have not filled out the help template, so the only detail I have about your system environment / install is what I can see in the screenshots. It looks like the Caddy binary you’re running via systemd is in /usr/bin/caddy.

You can double-check whether the http.handlers.mercure module is installed by running:

/usr/bin/caddy list-modules

If the module is not present, you will need to follow the xcaddy / download page links provided in the documentation to compile Caddy with the module installed before you can use it.

2 Likes

Thanks for the help, after installing xcaddy and tried to installed the module based on download page in caddy info.

But i end up getting another error.

You need to use Go version 1.15 or higher. 1.16 recommended. You’re on Go 1.14.

1 Like

Well, i have just pumped up to the latest version of 1.16, now xcaddy works. But i get another weird issue, XCADDY says, it has installed the module “mercure”, but still can’t find it on the module list?

Now check the module list, no mercure in it.

You’ll have to ask on the mercure project repo.

But according to the docs:

You should run this:

xcaddy build \
  --with github.com/dunglas/mercure \
  --with github.com/dunglas/mercure/caddy

DONE that too, still nothing in the module list.


Are you in /usr/bin when you run xcaddy? If not, you’re running the wrong binary.

Yes i was in /usr/bin when running Xcaddy. But still i cant find the mercure module on the list.

Check the screenshot for /usr/bin

The previous screenshots show you in ~ (home).

Yeah i was, but now i tried your way, but still the same. Nothing helping me to get this installed. Help me out, thanks.

You need to move the caddy binary to /usr/bin/caddy after building it. Doesn’t look like you did that. By default, it outputs the binary to your current directory.

1 Like