Reload Caddy config for one website

1. The problem I’m having:

I want to reload only one specific website , and not all Caddy ( it is like gracefull vhost restart in Apache for example ) , is there any way to do it ? or it is not possible ?

for example if you see the code below , i want to reload only test1.mehdikammakh.com because I changed the listening port from 8080 to 80

2. Error messages and/or full log output:

3. Caddy version:

v2.5.2

4. How I installed and ran Caddy:

Docker

a. System environment:

Docker

b. Command:

c. Service/unit/compose file:

d. My complete Caddy config:

{
        # Global options block. Entirely optional, https is on by default
        # Optional email key for lets encrypt
        email test@mehdikammakh.com
        # Optional staging lets encrypt for testing. Comment out for production.
        # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
(common) {
        header /* {
                -Server
                -x-powered-by
                -x-debug-token
                -x-debug-token-link
                -x-robots-tag
                Host {host}
                X-Real-IP {remote}
                X-Forwarded-For {remote}
        }
}
test1.mehdikammakh.com {
        handle {
                reverse_proxy test-d:80
        }
        log {
                output file /var/log/caddy/test1.mehdikammakh.com-access.log
                format json
        }
        import common
}
test2.mehdikammakh.com {
        handle {
                reverse_proxy test-m:80
        }
        log {
                output file /var/log/caddy/test2.mehdikammakh.com-access.log
                format json
        }
        import common
}

5. Links to relevant resources:

Why do you need this? Caddy’s restarts are graceful (with the exception of very long-lived websockets, which will be improving in a later version, at the expense of higher memory usage).

1 Like

I do not want to restart all Caddy so it can make from 5 to 10 seconds outage as there can be people already working on some of the websites
I want only to reload a specific website config
for example: caddy reload site1 , so it cannot take affect for other website in the config

Like Matt said, reloading Caddy is already graceful. What’s the actual problem you’re seeing?

1 Like

there is no problem or issue , I want to know if it is possible to only reload the config for one specific website.
thank you

1 Like

There is no practical difference though. If a config reload is graceful for all sites (which it is), it shouldn’t be a concern.

Like Matt said, the only downside right now is WebSocket connections get closed during a reload because they need to be so that Caddy can clean up resources.

1 Like

But why?

Wondering if a solution could not be to have separate configs for each website, launching various caddy instances, then being able to relaunch one config without touching stable instances ?

I have caddy in a lxc container on proxmox, reverse proxying to other containers with websites, so it feels it could break everything in case of reloading Caddyfile going wrong…

Or is it that a "graceful reload"reloads only the changed parts of caddyfile ?

You could, but that would certainly be much more complex to maintain. You would still need one instance in front to terminate TLS and route to other ones.

But the question remains, why do you need to reload the config? What is changing that you think requires a reload? And why do you think it needs to be isolated? Caddy config reloads are already graceful, there’s no problem.

See Architecture — Caddy Documentation to understand how Caddy is architected and how it manages config loading and changing.

2 Likes

To what problem though? :face_with_spiral_eyes: I’m still not clear on the problem.

If there’s any error loading a new config, the old config is gracefully reverted. You don’t have to do anything special or walk on eggshells. (We recommend testing all configs before deploying into production though, like a staging area.) (Maybe in the future we’ll run automated test suites against configs as part of the reload process – waiting for someone to fund this feature though.)

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