-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaddyfile
More file actions
165 lines (140 loc) · 4.91 KB
/
Caddyfile
File metadata and controls
165 lines (140 loc) · 4.91 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Caddyfile for Blue/Green Deployment
# Simple file-based environment switching for zero-downtime deployments
#
# The active environment is stored in /data/active_env file
# Switch environments by updating this file and reloading Caddy
#
# Switch to green: echo "green" > /data/active_env && caddy reload --config /etc/caddy/Caddyfile
# Switch to blue: echo "blue" > /data/active_env && caddy reload --config /etc/caddy/Caddyfile
# Check current: cat /data/active_env
{
# Global options
admin localhost:2019
log {
output stdout
format json
level INFO
}
}
# Main site - adjust domain as needed
clpr.tv {
# SSL/TLS (automatic with Let's Encrypt)
# tls you@example.com
# Global security headers
header {
# HSTS
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# Site isolation headers (Spectre mitigation)
Cross-Origin-Opener-Policy "same-origin"
Cross-Origin-Resource-Policy "same-origin"
# Cross-Origin-Embedder-Policy "require-corp" # Uncomment if you need stronger isolation
# XSS and content type protection
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
X-XSS-Protection "1; mode=block"
Referrer-Policy "strict-origin-when-cross-origin"
# Content Security Policy - REPORT-ONLY mode for 24-48h monitoring
# Monitor browser console for violations before switching to enforced mode
Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self' https: wss:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; upgrade-insecure-requests"
# ENFORCED CSP - uncomment after 24-48h of monitoring report-only mode
# Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self' https: wss:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; upgrade-insecure-requests"
# Remove server identification
-Server
}
# Access log
log {
output file /var/log/caddy/access.log {
roll_size 100mb
roll_keep 10
}
}
# Matchers for different content types
@static {
path /assets/* *.js *.css *.jpg *.jpeg *.png *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
}
@manifest {
path /manifest.json /site.webmanifest
}
@seo {
path /robots.txt /sitemap.xml /ads.txt
}
@html {
path / /*.html
not path /health.html
}
# Caching headers for hashed static assets (immutable)
header @static {
Cache-Control "public, max-age=31536000, immutable"
}
# Manifest files (cache for 1 hour)
header @manifest {
Cache-Control "public, max-age=3600"
}
# SEO files (cache for 1 day)
header @seo {
Cache-Control "public, max-age=86400"
}
# HTML files - no caching for SPA shell
header @html {
Cache-Control "no-store, must-revalidate"
}
# API routes -> backend
handle /api/* {
# Blue backend (default)
reverse_proxy clipper-backend-blue:8080 {
header_up Host {host}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
health_uri /health
health_interval 30s
health_timeout 10s
health_status 200
}
# Uncomment to switch to green:
# reverse_proxy clipper-backend-green:8080 {
# header_up Host {host}
# header_up X-Real-IP {remote_host}
# header_up X-Forwarded-For {remote_host}
# header_up X-Forwarded-Proto {scheme}
#
# health_uri /health
# health_interval 30s
# health_timeout 10s
# health_status 200
# }
}
# Health check endpoint (bypasses caching)
handle /health {
reverse_proxy clipper-backend-blue:8080
# Switch to green:
# reverse_proxy clipper-backend-green:8080
}
# WebSocket support
handle /ws/* {
reverse_proxy clipper-backend-blue:8080 {
header_up Upgrade {>Upgrade}
header_up Connection {>Connection}
}
# Switch to green:
# reverse_proxy clipper-backend-green:8080 {
# header_up Upgrade {>Upgrade}
# header_up Connection {>Connection}
# }
}
# Frontend (SPA)
handle /* {
reverse_proxy clipper-frontend-blue:80 {
health_uri /health.html
health_interval 30s
}
# Switch to green:
# reverse_proxy clipper-frontend-green:80
}
# Compression
encode gzip
}
# HTTP to HTTPS redirect
http://clpr.tv {
redir https://{host}{uri} permanent
}