部署笔记
写给未来的自己:这个站是怎么从本地一个文件夹,变成你能打开的网址的。
服务商
阿里云 ECS
域名
turgidcat.space
站点目录
/var/www/personal-site
产物
dist/
01
构建
本地跑构建,产物全在 dist/。纯静态,没有服务端。
npm run build 02
上传
只传变动的文件。这个目录底下还住着几个独立子应用(projects/*),
它们不在 Astro 的产物里——整包覆盖会把它们冲掉。
# 只上传变动文件,避免覆盖服务器上的运行时数据
tar czf /tmp/site.tar.gz -C dist index.html 404.html about blog projects changelog _astro
scp /tmp/site.tar.gz root@SERVER_IP:/tmp/
ssh root@SERVER_IP "cd /var/www/personal-site && tar xzf /tmp/site.tar.gz" 03
nginx
站点配置大致长这样,重点是 try_files 和 404 的兜底。
server {
listen 443 ssl http2;
server_name turgidcat.space;
root /var/www/personal-site;
index index.html;
location / {
try_files $uri $uri/ $uri.html =404;
}
error_page 404 /404.html;
location ~* \.(css|js|svg|png|jpg|jpeg|ico|woff2?)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
} 04
HTTPS
证书是 certbot 签的,到期自动续。
certbot --nginx -d turgidcat.space
certbot renew --dry-run 05
出问题时先看这几条
- DNS 的 A 记录要指向服务器公网 IP。
- 阿里云安全组要放行 22 / 80 / 443。
- 上传后页面没变:先强刷,再看 index.html 的时间戳。
- 出现 403:执行 chown -R www-data:www-data 站点目录。
- 站点根下若有独立子应用(如 projects/*),整包覆盖前先确认它们不属于本次构建产物。
备案号 鄂ICP备2026019613号-1 常驻在每个页面底部,别弄丢。