Caddy: Configurable data directory

Created on 22 Jun 2020  ยท  6Comments  ยท  Source: caddyserver/caddy

Currently the only place Caddy will save its data is in $HOME, would be nice if this can be customized (by other means than changing the user's home directory), e.g. with a flag.

Also, if/when you do implement this, please don't treat the directories within like hidden files when this option is provided, e.g. instead of this:

/var/lib/caddy
โ”œโ”€โ”€ .config/
โ”‚ย ย  โ””โ”€โ”€ caddy/
โ”‚ย ย      โ””โ”€โ”€ autosave.json
โ””โ”€โ”€ .local/
 ย ย  โ””โ”€โ”€ share/
 ย ย      โ””โ”€โ”€ caddy/
 ย ย          โ”œโ”€โ”€ acme/
 ย ย          โ”œโ”€โ”€ certificates/
 ย ย          โ”œโ”€โ”€ locks/
 ย ย          โ””โ”€โ”€ ocsp/

then this:

/var/lib/caddy
โ”œโ”€โ”€ autosave.json
โ”œโ”€โ”€ acme/
โ”œโ”€โ”€ certificates/
โ”œโ”€โ”€ locks/
โ””โ”€โ”€ ocsp/

The current implementation is understandable when it's being run as a user, but not as a service by the system, as it mostly is.

(Extra awesome if this could make it to 2.1 ๐Ÿ˜ƒ)

invalid

All 6 comments

Figured it's _kind of_ possible by setting both XDG_CONFIG_HOME and XDG_DATA_HOME to /var/lib, but that's not a good solution.

Thanks for the question. You can change Caddy's storage to _anything_, any folder on your disk, or even a database or any other backend storage module, with or without environment variables: https://caddyserver.com/docs/json/storage/

This has been configurable since the very beginning.

I fail to see how to use this, could you elaborate with an example?

Just like the docs show, verbatim:

{
    "storage": {
        "module": "file_system",
        "root": "/foo/bar"
    }
}

Any further questions about how to use Caddy should go on our forums: https://caddy.community

For anyone finding this in the future, this is how you configure this in a Caddyfile:

{
    storage file_system {
        root /var/lib/caddy
    }
}

# rest of your Caddyfile

The autosave.json file will still be using $HOME though.

For anyone finding this in the future, this is how you configure this in a Caddyfile:

{
    storage file_system {
        root /var/lib/caddy
    }
}

# rest of your Caddyfile

The autosave.json file will still be using $HOME though.

Correction, Caddy adheres to the XDG convention and uses XDG_DATA_HOME, not necessarily $HOME.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

la0wei picture la0wei  ยท  3Comments

SteffenDE picture SteffenDE  ยท  3Comments

jgsqware picture jgsqware  ยท  3Comments

xfzka picture xfzka  ยท  3Comments

PhilmacFLy picture PhilmacFLy  ยท  3Comments