Skip to content

Latest commit

 

History

History
111 lines (99 loc) · 2.64 KB

README.md

File metadata and controls

111 lines (99 loc) · 2.64 KB

Caddy Config Loader from Storage

Caddy supports dynamic config loading as part of an experimental feature that was introduced in v2.4.0. This module tells Caddy to load its configuration from any Caddy storage module. This means it's possible to store Caddy configuration in any caddy-compatible storage, e.g. database, s3, file_system, memory, encrypted, or any module that's part of the caddy.storage. namespace, and then load it into Caddy dynamically. This is useful for use-cases where you want to store your Caddy configuration in a database, or any form of shared location with multiple Caddy instances.

Example

Loading JSON configuration

This configuration file combination eventually configures Caddy to respond with `OK`. Store this configuration file in caddy storage under the key `config/caddy.json`
{
	"admin": {
		"listen": "localhost:2999"
	},
	"apps": {
		"http": {
			"http_port": 9080,
			"https_port": 9443,
			"servers": {
				"srv0": {
					"listen": [
						":8443"
					],
					"routes": [
						{
							"match": [
								{
									"host": [
										"localhost"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"body": "OK!",
													"handler": "static_response"
												}
											]
										}
									]
								}
							],
							"terminal": true
						}
					]
				}
			}
		},
		"pki": {
			"certificate_authorities": {
				"local": {
					"install_trust": false
				}
			}
		}
	}
}

Run Caddy with the following config:

{
	"admin": {
		"listen":"localhost:2019",
		"config": {
			"load": {
				"module": "storage"
			}
		}
	}
}

Loading Caddyfile configuration

This configuration file combination eventually configures Caddy to respond with `OK`. Store this configuration file in caddy storage under the key `config/Caddyfile`
example.com {
	respond "Howdy!"
}

Run Caddy with the following config:

{
	"admin": {
		"listen":"localhost:2019",
		"config": {
			"load": {
				"module": "storage",
				"adapter": "caddyfile",
				"key": "config/Caddyfile"
			}
		}
	}
}