Caddy 2 is a modern, powerful, enterprise-grade open-source web server designed for simplicity, security, and flexibility. It’s unique in its ability to automatically manage HTTPS by default, without any complex configuration.
- Add-on Installation
- Basic Setup Examples
- Configuration Options
- Advanced Usage: Custom Binaries & Plugins
To install the Caddy 2 add-on, first add the repository to your Hass.io instance by entering the following URL:
https://github.com/einschmidt/hassio-addons
If you encounter any issues, refer to the official documentation for guidance.
Once the repository is added, search for and install the "Caddy 2" add-on.
The Caddy 2 add-on offers multiple setup methods to accommodate different environments and network configurations. These setups range from simple to more complex, allowing you to choose the level of customization that fits your needs.
By default, Caddy 2 runs as a proxy server for Home Assistant without needing a Caddyfile
. It uses the configuration provided in the add-on settings and automatically handles HTTPS for you.
Note: If a Caddyfile
is found in the configuration directory, the non_caddyfile_config
settings will be ignored in favor of the Caddyfile.
Important: Always restart the add-on after making changes to the configuration.
For a basic proxy setup, forwarding yourdomain.com
to Home Assistant, use the following example (without a Caddyfile
):
non_caddyfile_config:
email: your@email.com
domain: yourdomain.com
destination: localhost
port: 8123
log_level: info
args: []
env_vars: []
Note: These examples are for guidance only. Customize them according to your needs.
For more advanced customization, you can create and use a Caddyfile to define your proxy server's configuration. This allows greater control over settings such as routing, headers, and SSL management.
To use a Caddyfile, place the file in the add-on configuration directory. You can access this directory using either the SSH or Samba add-ons. The add-on will only search for the Caddyfile in this specific location.
The Caddyfile needs to be placed in the add-on's configuration directory, which can be found at:
/addon_configs/c80c7555_caddy-2
SSH: You can access the configuration directory via SSH by navigating to /addon_configs/
.
Samba: Alternatively, with the Samba add-on, you can access this folder from your network as a shared directory. Look for the addon_configs
folder and locate the appropriate directory.
Caddy 2 can automatically generate SSL certificates. If you want to use certificates from other add-ons (such as the Let’s Encrypt add-on), they can be placed in the /ssl
directory. The Caddy 2 add-on will have access to this folder, allowing you to use external certificates or create certificates for other services.
A simple Caddyfile for proxying traffic to a Home Assistant installation might look like this:
{
email your@email.com
}
yourdomain.com {
reverse_proxy localhost:8123
}
For more advanced configurations, refer to the Caddyfile documentation.
Important: Restart the add-on after changing the configuration.
To instruct the add-on to use and monitor the Caddyfile
, your configuration should look like this:
non_caddyfile_config: {}
log_level: info
args:
- "--watch"
env_vars: []
Note: Customize this example for your specific setup.
For advanced users, you can replace the default Caddy binary with a custom one. Place your caddy
binary in the add-on configuration directory, using SSH or Samba. The add-on will use binaries found in this folder.
Important: Restart the add-on after any configuration changes.
Here’s an example configuration using a custom Caddy binary and a Caddyfile
, with automatic updates and formatting enabled:
non_caddyfile_config: {}
log_level: info
args:
- "--watch"
env_vars: []
caddy_upgrade: true
caddy_fmt: true
Note: These examples are meant for reference. Adjust them to match your setup.
Defines the email address used when creating an ACME account with your Certificate Authority (CA). This is recommended to help manage certificates in case of issues.
Note: This option is only used for the default reverse proxy setup. It will be ignored once a Caddyfile
is found in the configuration directory.
Specifies the domain name for your setup.
Note: This option is only applicable to the default reverse proxy setup and will be ignored if a Caddyfile
is present in the configuration directory.
Sets the upstream address for the reverse proxy. Typically, localhost
is sufficient for most setups. To target specific addresses, you can use 127.0.0.1
for IPv4 or ::1
for IPv6.
Note: This option is only used for the default reverse proxy setup and is ignored if a Caddyfile
is found in the configuration directory.
Defines the port for the upstream address. For example, Home Assistant typically uses port 8123
.
Note: This setting is only applied in the default reverse proxy configuration. It is ignored if a Caddyfile
is present in the configuration directory.
Enables automatic upgrades for custom Caddy binaries and their plugins. Set this option to true
to allow updates, or false
to disable it. The default is false
.
Note: This feature only applies to custom binaries (Caddy version 2.4 or higher) and is not needed if using the default Caddy binary.
Enables automatic formatting and prettifying of the Caddyfile
. Set this option to true
to enable formatting or false
to disable it. By default, it is disabled.
Note: This feature requires a valid Caddyfile
to work.
Allows you to specify additional command-line arguments for Caddy 2. Add one or more arguments to the list, and they will be executed each time the add-on starts.
Note: The --config
argument is automatically added. For more information, refer to the official Caddy documentation.
Allows you to define multiple environment variables, usually used for custom Caddy binary builds. These variables can be set in the following format:
Example:
env_vars:
- name: NAMECHEAP_API_USER
value: xxxx
- name: NAMECHEAP_API_KEY
value: xxxx
Specifies the name of the environment variable.
Specifies the value assigned to the environment variable.
Controls the verbosity of the log output from the add-on. This setting is useful for debugging or monitoring the add-on’s behavior. Available log levels are:
trace
: Shows detailed information, including all internal function calls.debug
: Provides extensive debugging information.info
: Shows typical events and information.warning
: Logs unexpected situations that are not errors.error
: Records runtime errors that don’t need immediate action.fatal
: Critical errors that make the add-on unusable.
Each level includes the messages from more severe levels. For example, debug
also includes info
messages. The default setting is info
, which is recommended unless troubleshooting.
This add-on uses a single binary file to launch Caddy, which makes it highly customizable. You can run a custom build of Caddy with any version and plugins you need, providing maximum flexibility for advanced users.
To build your own version of Caddy, including specific plugins or features, you can follow the instructions provided in the official Caddy documentation using the xcaddy
tool. This allows you to compile your own version of Caddy with custom modules or plugins that are not included in the default binary.
To use a custom-built Caddy binary, follow these steps:
- Build your custom Caddy binary using
xcaddy
or obtain a pre-built version that suits your needs. - Place the
caddy
binary file into the add-on configuration folder. - Restart the Caddy 2 add-on to begin using your custom version of Caddy.
The add-on configuration folder can be found at:
/addon_configs/c80c7555_caddy-2
This is where you should place your custom caddy
binary and any related configuration files.
Once the add-on is restarted, Caddy will use the custom binary you've provided, allowing you to leverage any additional features or plugins included in your custom build.