Autoload caddy configuration on system reboot

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

Caddy configuration is load from JSON file using the curl endpoint.

a. System environment:

AWS EC2 (Ubuntu 20.04)

b. Command:

curl localhost:2019/load -H 'Content-Type: application/json' -d @final_with_headers.json

c. Service/unit/compose file:

paste full file contents here

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
or helpers will be sad

3. The problem I’m having:

Many times, I need to stop-start the EC2 instance. Every time after the restart, the caddy configuration needs to be loaded manually by SSH to the server.

How can I auto-load the configuration file whenever the server is restarted. Just like other proxy providers (apache, nginx), their configuration can be saved inside /etc/nginx/ directory, is there such a way in the Caddy?

Also planning to use auto-scaling to automatically provision new instances on load. Without auto loading, everything a new instance is launched, I need to manually load the configuration.

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Use the --resume flag: Command Line — Caddy Documentation

You should probably be using the caddy-api service that the .deb ships with, instead of the caddy service. It’s optimized for running Caddy when primarily using the API. See the note here in the docs:

Do I need to use --resume every time the system reboots? If yes, how still it requires manual work to resume the same configuration.

If you use the caddy-api.service it will automate that for you.

Thanks, @francislavoie Is there any guide on how to set up the caddy-api service and how to configure it to load specif configuration on boot?
The installation guide only gives the installation guide and not the configuration guide.

Just run systemctl disable caddy then systemctl enable caddy-api.

Thanks, @francislavoie Where will be the config (final_with_headers.json in my case) will be placed so that it will be loaded automatically? Do I need to provide the path to the config? Currently, it is placed in /home/user/final_with_headers.json.

I check the doc dist/caddy-api.service at master · caddyserver/dist · GitHub but it’s not clear where to place the configuration file.

You can put it anywhere you like. You’ll push your initial config using curl:

curl -X POST "http://localhost:2019/load" \
	-H "Content-Type: application/json" \
	-d @caddy.json

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