Skip to content

Commit 5df7834

Browse files
author
Alcides Ramos
committed
fix: Updated Caddyfile
using proper snippet composition
1 parent 720e619 commit 5df7834

File tree

7 files changed

+68
-80
lines changed

7 files changed

+68
-80
lines changed

docker/caddy/Caddyfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import snippets/*
66

77
{$CADDY_HOSTNAME} {
8+
import strip-www
89
import common
10+
import cache
11+
import security
912
import ssl
10-
import domain
13+
import not-found
1114

1215
root * /var/www/html/public
16+
17+
import php-fastcgi
1318
}

docker/caddy/snippets/cache

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(cache) {
2+
header {
3+
Cache-Control "public, max-age=31536000"
4+
}
5+
6+
@static {
7+
file
8+
path *.avif *.ico *.css *.js *.gz *.eot *.ttf *.otf *.gif *.webp *.avif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.pdf
9+
}
10+
header @static Cache-Control "max-age=31536000,public,inmutable"
11+
12+
@html {
13+
path *.html *.htm
14+
}
15+
header @html {
16+
Cache-Control "public, max-age=43200"
17+
}
18+
}

docker/caddy/snippets/domain

Lines changed: 0 additions & 79 deletions
This file was deleted.

docker/caddy/snippets/not-foud

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(not-found) {
2+
@static_404 {
3+
path_regexp \.(jpg|jpeg|png|webp|gif|avif|ico|svg|css|js|gz|eot|ttf|otf|woff|woff2|pdf)$
4+
not file
5+
}
6+
respond @static_404 "Not Found" 404 {
7+
close
8+
}
9+
}

docker/caddy/snippets/php-fastcgi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(php-fastcgi) {
2+
php_fastcgi {$CADDY_PHPFPM_GATEWAYS} {
3+
index index.php
4+
5+
resolve_root_symlink
6+
7+
lb_policy round_robin
8+
}
9+
}

docker/caddy/snippets/security

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(security) {
2+
header {
3+
Strict-Transport-Security "max-age=31536000;includeSubDomains;preload"
4+
X-Frame-Options "SAMEORIGIN"
5+
X-Xss-Protection "1;mode=block"
6+
Referrer-Policy "no-referrer-when-downgrade"
7+
X-Content-Type-Options "nosniff"
8+
Permissions-Policy "autoplay=(self),camera=(),geolocation=(),microphone=(),payment=(),usb=()"
9+
10+
# Review
11+
#?Content-Security-Policy "default-src 'self';script-src 'self';style-src 'self'"
12+
}
13+
14+
@excludedMethods {
15+
not method GET HEAD POST OPTIONS
16+
}
17+
respond @excludedMethods "Not Allowed" 405 {
18+
close
19+
}
20+
}

docker/caddy/snippets/strip-www

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(strip-www) {
2+
@strip_www {
3+
header_regexp www Host ^www\.(.*)$
4+
}
5+
redir @strip_www https://{http.regexp.www.1}{uri}
6+
}

0 commit comments

Comments
 (0)