Repository navigation
Expand file tree
/
Copy pathcaddyfile.example
More file actions
104 lines (89 loc) · 3.66 KB
/
Copy pathcaddyfile.example
File metadata and controls
104 lines (89 loc) · 3.66 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Example Caddyfile for the caddy-waf module (http.handlers.waf).
# Every directive below is recognised by the Caddyfile parser in config.go.
{
auto_https off
admin localhost:2019
}
# ---------------------------------------------------------------------------
# Example 1: minimal setup
# ---------------------------------------------------------------------------
example.com {
route {
waf {
rule_file rules.json
ip_blacklist_file ip_blacklist.txt
dns_blacklist_file dns_blacklist.txt
metrics_endpoint /waf_metrics
anomaly_threshold 10
log_severity info
log_path /var/log/caddy/waf.log
# Rotation is on by default (100 MiB, keep 10, gzip); tune or disable:
log_roll {
size_mb 50
keep 5
compression zstd
}
}
respond "Hello, World — protected by Caddy WAF" 200
}
}
# ---------------------------------------------------------------------------
# Example 2: API gateway with rate limiting, GeoIP, ASN block, and
# custom responses
# ---------------------------------------------------------------------------
api.example.com {
route {
waf {
metrics_endpoint /waf_metrics
anomaly_threshold 15
# One or more rule files (the directive may repeat).
rule_file rules/sql-injection.json
rule_file rules/xss.json
rule_file rules/lfi.json
# Per-IP rate limiting on /api/* and /admin/*.
rate_limit {
requests 100
window 10s
cleanup_interval 5m
paths ^/api/.* ^/admin/.*
match_all_paths false
}
# Country and ASN gating (require GeoLite2 MMDB files).
block_countries GeoLite2-Country.mmdb RU CN KP
block_asns GeoLite2-ASN.mmdb 14618 16509
# Tor exit-node blocking; refreshed every 24h, retries every hour
# on transient failures.
tor {
enabled true
tor_ip_blacklist_file tor_blacklist.txt
update_interval 24h
retry_on_failure true
retry_interval 1h
}
# IP and DNS blacklists.
ip_blacklist_file ip_blacklist.txt
dns_blacklist_file dns_blacklist.txt
# Custom responses for blocked requests.
# form 1: status content-type "inline body…"
# form 2: status content-type /path/to/body.file
custom_response 403 application/json error.json
custom_response 429 text/plain "Slow down."
# Body size ceilings, in bytes.
# max_request_body_size caps request body reads (io.LimitReader).
# max_response_body_size caps how much of the response body is held
# in memory for Phase 4 inspection; past
# this the response is streamed through
# un-inspected instead of buffered.
# Both default to 10 MiB (10485760).
max_request_body_size 10485760
max_response_body_size 10485760
# Logging.
log_severity info
log_json
log_path /var/log/caddy/waf.log
log_buffer 2000
redact_sensitive_data
}
reverse_proxy localhost:8080
}
}