Skip to content

Commit c68f9f4

Browse files
committed
fix: refactor Caddyfile with handle blocks to fix health checks
1 parent 3100e4e commit c68f9f4

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

config/Caddyfile

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,39 @@
1717

1818
# ── Site Block ────────────────────────────────────────────────────────────────
1919
:80 {
20-
# Allow health check endpoint without domain restriction
21-
@health path /health
22-
reverse_proxy @health localhost:8080
20+
# Handle health checks first
21+
handle /health {
22+
respond "OK" 200
23+
}
2324

2425
# Block requests not matching allowed domains (if CADDY_DOMAINS is set)
25-
@blocked not host {$CADDY_DOMAINS:*}
26-
abort @blocked
26+
@blocked {
27+
not host {$CADDY_DOMAINS:*}
28+
}
29+
handle @blocked {
30+
abort
31+
}
2732

28-
encode zstd gzip
33+
# Main application handling
34+
handle {
35+
encode zstd gzip
2936

30-
# Security headers
31-
header / {
32-
Strict-Transport-Security "max-age=31536000;"
33-
X-XSS-Protection "1; mode=block"
34-
X-Frame-Options "DENY"
35-
X-Robots-Tag "noindex, nofollow"
36-
X-Content-Type-Options "nosniff"
37-
-Server
38-
-X-Powered-By
39-
-Last-Modified
40-
}
37+
# Security headers
38+
header {
39+
Strict-Transport-Security "max-age=31536000;"
40+
X-XSS-Protection "1; mode=block"
41+
X-Frame-Options "DENY"
42+
X-Robots-Tag "noindex, nofollow"
43+
X-Content-Type-Options "nosniff"
44+
-Server
45+
-X-Powered-By
46+
-Last-Modified
47+
}
4148

42-
# Reverse proxy
43-
reverse_proxy localhost:8080 {
44-
header_up X-Real-IP {http.request.header.CF-Connecting-IP:{http.request.header.Fly-Client-IP:{remote_host}}}
45-
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP:{http.request.header.Fly-Client-IP:{remote_host}}}
49+
# Reverse proxy
50+
reverse_proxy localhost:8080 {
51+
header_up X-Real-IP {http.request.header.CF-Connecting-IP:{http.request.header.Fly-Client-IP:{remote_host}}}
52+
header_up X-Forwarded-For {http.request.header.CF-Connecting-IP:{http.request.header.Fly-Client-IP:{remote_host}}}
53+
}
4654
}
4755
}

0 commit comments

Comments
 (0)