Files
coolcoth.com/deploy/nginx-security-headers.conf
2026-08-08 15:53:53 +08:00

30 lines
1.7 KiB
Plaintext
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.
# ============================================================
# 酷冰甲 CMS / coolcoth.com — 宝塔 Nginx 安全响应头片段
# 用法:宝塔 → 网站 → 设置 → 配置文件,在 server { ... } 块内、
# location / { ... } 之前(或之内)整段粘贴即可。
# 说明:always 必须加,否则 4xx/5xx 和静态文件不会带这些头。
# ============================================================
# 缺失项补齐(审计 P2
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=(), payment=(), usb=(), interest-cohort=()" always;
add_header X-Frame-Options "SAMEORIGIN" always;
# HSTS 升级:含子域 + preload(审计当前线上仅 max-age=31536000
# ⚠️ 若 宝塔「SSL」面板已自动下发 HSTS,请删掉那一处,避免重复下发两条。
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# CSP(含动态 nonce)无法在 Nginx 静态下发,继续由 PHP 层 apply_security_headers() 输出,勿在此重复。
# ============================================================
# 源站隐身(curl --resolve 直连 200 的治理,需配合 CDN)
# 仅当已接入 EdgeOne / Cloudflare 后启用:仅放行 CDN 回源 IP 段。
# 例(Cloudflare,需替换为你实际接入的 CDN 回源段;EdgeOne 用其官方回源 IP 列表):
# allow 173.245.48.0/20;
# allow 103.21.244.0/22;
# ...(完整段见 CDN 官方文档)
# deny all;
# 注:未接入 CDN 前不要写 deny all,否则正常用户也进不来。
# ============================================================