umi-test/docker/Caddyfile
2025-02-26 10:53:26 +08:00

62 lines
1.4 KiB
Caddyfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:80 {
root * /usr/share/caddy
file_server {
precompressed br gzip
}
encode {
gzip
}
# 安全头配置保持不变
header /* {
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
}
# 缓存策略优化
header {
# 默认动态内容不缓存
Cache-Control "no-cache, must-revalidate"
# 静态资源缓存(改进正则表达式)
@static {
path_regexp \.(?:css|js|png|jpe?g|gif|ico|svg|woff2?|ttf|eot|web[pm]|avif)$
}
header @static Cache-Control "public, max-age=31536000, immutable"
}
# SPA路由处理优化通用方案
@spa {
not file
}
rewrite @spa /index.html
# 日志配置(保持精简)
log {
output stdout
format json {
time_format iso8601
}
format filter {
fields {
request>remote_ip delete
request>remote_port delete
request>proto delete
request>method delete
request>headers delete
resp_headers delete
}
wrap json
}
}
# 错误处理
handle_errors {
@404 {
expression {http.error.status_code} == 404
}
respond @404 "Not Found" 404
}
}