Caddy v2 examples

It’s been a while since I started using caddy v2 in production. Therefore I would like to show some caddy configuration examples that I also use by myself.

HTTP3 in Caddy v2

In the last caddy post I mentioned how to setup HTTP3, however the syntax has changed slightly.

1
2
3
4
5
6
7
{
servers :443 {
protocol {
experimental_http3
}
}
}

Reverse proxy

Simple reverse proxy (to a specific port)

1
2
3
matrix.rmsol.de {
reverse_proxy localhost:8008
}

File server

Serving a static page (html/css). In that case with gzip and extended Cache-Control.

1
2
3
4
5
6
rmsol.de {
root * /var/www/rmsol.de
encode gzip
header Cache-Control max=age=3600
file_server
}

PHP website

Serving a PHP website.

1
2
3
4
5
ip-whois.de {
root * /var/www/ip-whois.de
file_server
php_fastcgi unix//var/run/php/php7.4-fpm.sock
}

Nextcloud

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
nextcloud.rmsol.de {
root * /var/www/nc
file_server

php_fastcgi unix//var/run/php/php7.4-fpm.sock
header {
Strict-Transport-Security max-age=31536000; # enable HSTS
}

redir /.well-known/carddav /remote.php/dav 301
redir /.well-known/caldav /remote.php/dav 301

@forbidden {
path /.htaccess
path /data/*
path /config/*
path /db_structure
path /.xml
path /README
path /3rdparty/*
path /lib/*
path /templates/*
path /occ
path /console.php
}

respond @forbidden 404
}