caddy run command starts the Caddy server and blocks indefinitely, running Caddy in the foreground (daemon mode). This is the most common way to run Caddy in production.
Usage
Description
Starts the Caddy process, optionally bootstrapped with an initial config file, and blocks indefinitely until the server is stopped. This runs Caddy in “daemon” mode where it stays in the foreground. If a config file is specified, it will be applied immediately after the process is running. If the config file is not in Caddy’s native JSON format, you can specify an adapter with--adapter to adapt the given config file to Caddy’s native format.
Special Case: If the current working directory has a file called
Caddyfile and the caddyfile config adapter is plugged in (default), then that file will be loaded and used to configure Caddy, even without any command line flags.Flags
Configuration file to load. Can be JSON or any format supported by an adapter. Use
- to read from stdin.If not specified and a Caddyfile exists in the current directory, it will be used automatically.Name of config adapter to apply. Required if the config file is not in JSON format.Common adapters:
caddyfile- Caddyfile format (default for files named Caddyfile)yaml- YAML format (if adapter is installed)
Environment file(s) to load in KEY=VALUE format. Can be specified multiple times.Variables from the envfile will not overwrite existing environment variables.
Print the environment as seen by the Caddy process before starting.This is the same as the
environ command but does not quit after printing. Useful for troubleshooting.Use saved config if any (prefers autosave over
--config file).The --resume flag will override the --config flag if there is a config autosave file. It is not an error if --resume is used and no autosave file exists.Watch config file for changes and reload it automatically.
Path of file to which to write the process ID.Useful for process management and monitoring.
Echo confirmation bytes to this address on success.This is used internally by
caddy start and should not be used directly.Examples
Run with default Caddyfile
Caddyfile exists in the current directory, Caddy will automatically load it.
Run with a specific config file
Run with JSON config
Run with config from stdin
Run with environment file
.env file:
Run with auto-reload on config changes
Resume from last saved config
Run and print environment
Exit Codes
0- Success1- Failed startup2- Failed quit (graceful shutdown failed)
Environment Variables
Caddy respects several environment variables:HOME/USERPROFILE- Used to determine default data directoriesXDG_DATA_HOME- Custom data directory (Unix)XDG_CONFIG_HOME- Custom config directory (Unix)XDG_CACHE_HOME- Custom cache directory (Unix)
If using environment variables in your config (e.g.,
{env.VARIABLE}), you can verify them with caddy environ or caddy run --environ.Implementation Details
The command performs the following steps:- Traps signals for graceful shutdown
- Sets up buffered logging for early startup
- Configures resource limits (GOMAXPROCS, memory limits)
- Loads environment files if specified
- Loads and adapts the configuration
- Creates PID file if requested
- Applies the configuration
- Sends pingback confirmation if requested (internal use)
- Watches config file for changes if
--watchis enabled - Blocks indefinitely until shutdown signal
Related Commands
caddy start- Start Caddy in the backgroundcaddy stop- Stop a running Caddy instancecaddy reload- Reload the configurationcaddy adapt- Test config adaptationcaddy validate- Validate a configuration file