-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaddyfile.example
More file actions
137 lines (121 loc) · 3.61 KB
/
Copy pathCaddyfile.example
File metadata and controls
137 lines (121 loc) · 3.61 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
:80 {
# 设置根目录为构建后的文件
root * /usr/share/caddy
# 处理 /vault 路径下的静态文件
handle_path /vault/* {
# 移除 /vault 前缀并从 vault 目录提供文件
root * /vault
file_server {
browse
}
# CDN 友好的缓存策略
# Markdown 文件 - 较短缓存,因为可能会更新
@markdown {
path *.md
}
header @markdown {
Cache-Control "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400"
Content-Type "text/plain; charset=utf-8"
}
# 图片文件 - 长期缓存
@images {
path *.jpg *.jpeg *.png *.gif *.webp *.svg *.ico
}
header @images {
Cache-Control "public, max-age=31536000, immutable"
Access-Control-Allow-Origin "*"
}
# 视频/音频文件 - 长期缓存
@media {
path *.mp4 *.webm *.mp3 *.wav *.ogg *.m4a
}
header @media {
Cache-Control "public, max-age=31536000, immutable"
Access-Control-Allow-Origin "*"
}
# 文档文件 - 中期缓存
@documents {
path *.pdf *.doc *.docx *.xls *.xlsx *.ppt *.pptx
}
header @documents {
Cache-Control "public, max-age=604800, s-maxage=2592000"
Access-Control-Allow-Origin "*"
}
# 地图/轨迹文件 - 中期缓存
@tracks {
path *.gpx *.kml *.kmz *.geojson
}
header @tracks {
Cache-Control "public, max-age=86400, s-maxage=604800"
Content-Type "application/xml; charset=utf-8"
Access-Control-Allow-Origin "*"
}
# JSON 文件 - 短期缓存
@json {
path *.json
}
header @json {
Cache-Control "public, max-age=600, s-maxage=3600"
Content-Type "application/json; charset=utf-8"
Access-Control-Allow-Origin "*"
}
# 字体文件 - 长期缓存
@fonts {
path *.woff *.woff2 *.ttf *.otf *.eot
}
header @fonts {
Cache-Control "public, max-age=31536000, immutable"
Access-Control-Allow-Origin "*"
}
# 压缩文件 - 中期缓存
@archives {
path *.zip *.tar *.gz *.7z *.rar
}
header @archives {
Cache-Control "public, max-age=604800"
}
}
# 处理其他所有请求
handle {
# 尝试文件,如果不存在则返回 index.html (SPA)
try_files {path} /index.html
file_server
}
# 启用 gzip 压缩
encode gzip
# 设置安全头部
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
X-XSS-Protection "1; mode=block"
}
# 为应用程序资源设置缓存策略
@app_js {
path *.js *.mjs
}
header @app_js {
Content-Type "application/javascript; charset=utf-8"
Cache-Control "public, max-age=31536000, immutable"
}
@app_css {
path *.css
}
header @app_css {
Content-Type "text/css; charset=utf-8"
Cache-Control "public, max-age=31536000, immutable"
}
# HTML 文件不缓存(总是获取最新版本)
@html {
path *.html /
}
header @html {
Cache-Control "no-cache, no-store, must-revalidate"
Pragma "no-cache"
Expires "0"
}
# 日志
log {
output stdout
format console
}
}