跳转到内容

部署配置参考

ShokaX 项目根目录下包含三个部署平台的配置文件,均已预配置好构建命令和安全头。

所有平台的共同配置:

配置项说明
构建命令bun run build两步构建:Astro 构建 + Pagefind 索引
输出目录distAstro 静态站点输出目录
框架类型astro平台自动识别

配置文件:vercel.json

{
"framework": "astro",
"installCommand": "bun install",
"buildCommand": "bun run build",
"outputDirectory": "dist",
"headers": [
{
"source": "/_astro/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
]
},
{
"source": "/(.*)",
"headers": [
{ "key": "Content-Security-Policy", "value": "frame-ancestors 'none';" },
{ "key": "X-Frame-Options", "value": "DENY" }
]
}
]
}
路径
/_astro/*Cache-Controlpublic, max-age=31536000, immutable
/*Content-Security-Policyframe-ancestors 'none'
/*X-Frame-OptionsDENY

/_astro/* 是 Astro 的静态资源路径,设置 1 年不可变缓存。

配置文件:netlify.toml

[build]
framework = "astro"
command = "bun install && bun run build"
publish = "dist"
[[headers]]
for = "/_astro/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/*"
[headers.values]
Content-Security-Policy = "frame-ancestors 'none';"
X-Frame-Options = "DENY"

配置文件:edgeone.json

{
"installCommand": "bun install",
"buildCommand": "bun run build",
"outputDirectory": "dist"
}
路径
/_astro/*Cache-Controlpublic, max-age=31536000, immutable
/*Strict-Transport-Securitymax-age=63072000; includeSubDomains; preload
/*Content-Security-Policyframe-ancestors 'none'
/*X-Frame-OptionsDENY

EdgeOne Pages 额外配置了 HSTS(HTTP Strict Transport Security),强制 HTTPS 访问。

作用
Cache-Control: immutable静态资源永不变化,浏览器无需重新验证
Content-Security-Policy: frame-ancestors 'none'禁止页面被嵌入 iframe,防止点击劫持
X-Frame-Options: DENY同上,兼容旧浏览器
Strict-Transport-Security强制 HTTPS,防止中间人攻击
平台部署按钮
VercelDeploy with Vercel
NetlifyDeploy to Netlify
EdgeOne PagesDeploy with EdgeOne Pages

部署后,在各平台的控制台中绑定自定义域名:

  1. Vercel:Settings → Domains
  2. Netlify:Domain settings → Custom domain
  3. EdgeOne Pages:域名管理 → 绑定域名

绑定后,记得修改 astro.config.mjs 中的 site 字段为你的自定义域名。

Cloudflare Pages 的详细部署指南请参见 Cloudflare 部署文档

如需部署到自有服务器,请参见 自托管部署文档

津 ICP 备2022001375 号
津公网安备 12011402001353 号