Tech - Business Tool, Personal Toys

Caddy 2 Caddyfile Usage

Some Caddy 2 Caddyfile examples.

Global Options

1
2
3
4
5
6
{
	# Turn off admin port
	admin off
	# Turn on http3
	experimental_http3
}

Multiple Domains

1
2
3
www.example.com test.example.com {
	...
}
1
2
3
old.example.com other.example.com {
	redir https://example.com{uri}
}

Error Handling

1
2
3
4
5
6
7
8
www.example.com {
	root * /www/site/www.example.com
	file_server
	handle_errors {
		rewrite * /{http.error.status_code}.html
		file_server
	}
}

Template

Create your own myip page.

/www/site/www.example.com/myip/index.html

1
{{.RemoteIP}}

Caddy will parse all files:

1
2
3
4
5
www.example.com {
	root * /www/site/www.example.com
	file_server
	templates
}

Caddy will parse files in /www/site/www.example.com/myip:

1
2
3
4
5
www.example.com {
	root * /www/site/www.example.com
	file_server
	templates /www/site/www.example.com/myip
}

Caddy will only parse /www/site/www.example.com/myip/index.html:

1
2
3
4
5
www.example.com {
	root * /www/site/www.example.com
	file_server
	templates /www/site/www.example.com/myip/index.html
}
John Siu
Update: 2020-06-26
comments powered by Disqus