The storage module provides an abstraction layer for persisting data in Caddy. This is primarily used by the TLS certificate management system to store certificates, private keys, OCSP staples, and other metadata.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/caddyserver/caddy/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Caddy’s storage system is modular and pluggable, allowing you to choose different storage backends based on your infrastructure needs.Storage Interface
All storage modules must implement thecertmagic.Storage interface, which provides:
- Store - Save data to storage
- Load - Retrieve data from storage
- Delete - Remove data from storage
- Exists - Check if data exists
- List - List keys in storage
- Stat - Get metadata about stored data
- Lock/Unlock - Distributed locking for coordination
Default Storage
By default, Caddy uses file system storage located at:Linux/Unix:
macOS:
Windows:
Android:
~/.local/share/caddymacOS:
~/Library/Application Support/CaddyWindows:
%AppData%\CaddyAndroid:
/sdcardXDG_DATA_HOME environment variable:
File System Storage
Module ID:caddy.storage.file_system
The default storage backend stores data on the local file system.
Configuration
Root directory for storage. Defaults to
AppDataDir().Directory Structure
The file system storage organizes data as follows:Storage Converter Interface
Custom storage modules must implement theStorageConverter interface:
Global vs. Module-Specific Storage
You can configure storage at different levels:Global Storage
Set storage for all apps:Per-CA Storage
Different storage for specific certificate authorities:- Keeping signing keys separate from leaf certificates
- Using different security policies for different CAs
- Isolating CA data for compliance requirements
Environment-Based Paths
Caddy respects standard environment variables for determining storage paths:Configuration Directory
Environment Variable:XDG_CONFIG_HOME
$XDG_CONFIG_HOME/caddy$HOME/.config/caddy(Linux/Unix)%AppData%\Caddy(Windows)$HOME/Library/Application Support/Caddy(macOS)./caddy(fallback)
Data Directory
Environment Variable:XDG_DATA_HOME
$XDG_DATA_HOME/caddy%AppData%\Caddy(Windows)$HOME/Library/Application Support/Caddy(macOS)$home/lib/caddy(Plan 9)$HOME/caddy(Android)$HOME/.local/share/caddy(Linux/Unix)./caddy(fallback)
Platform-Specific Paths
Caddy adapts storage paths to platform conventions:Windows: Uses
macOS: Uses
Linux: Follows XDG Base Directory Specification
Plan 9: Uses
Android: Uses
%AppData% or %USERPROFILE%macOS: Uses
~/Library/Application SupportLinux: Follows XDG Base Directory Specification
Plan 9: Uses
$home/libAndroid: Uses
/sdcardStorage Best Practices
Production Deployments
-
Use absolute paths for clarity:
-
Set appropriate permissions:
- Back up regularly - Storage contains private keys and certificates
- Monitor disk space - OCSP staples and certificate renewals generate data
Cluster Deployments
For multiple Caddy instances:- Use shared storage - Consider network file systems or database-backed storage
- Enable locking - Ensure distributed locking works correctly
- Test failover - Verify lock releases on instance failure
Security Considerations
Custom Storage Modules
You can implement custom storage backends for:- Cloud storage (S3, Azure Blob, Google Cloud Storage)
- Databases (Redis, MongoDB, PostgreSQL)
- Distributed systems (Consul, etcd)
- Encrypted storage
Registration
Register your storage module ininit():
Implementation
ImplementStorageConverter:
Autosave Configuration
Caddy can automatically persist the last active configuration: Default path:{config_dir}/autosave.json
Where {config_dir} is:
- Linux:
~/.config/caddy - macOS:
~/Library/Application Support/Caddy - Windows:
%AppData%\Caddy
Troubleshooting
Permission Errors
Problem:permission denied errors
Solution: Ensure Caddy has read/write access:
Lock Timeouts
Problem: “could not acquire lock” errors Solution:- Check for stale lock files in
{root}/locks/ - Ensure proper cleanup on Caddy shutdown
- Verify distributed locking works in cluster setups
Disk Space Issues
Problem: Running out of disk space Solution:- Monitor storage directory size
- Clean up old OCSP staples
- Implement log rotation if logging to storage