~/deploy-guide
部署指南
当前站点是 Astro 静态站,部署方式就是本地构建 `dist/`,上传到阿里云 ECS 的 nginx 站点目录,然后重载 nginx。
现有目标
服务商:阿里云 ECS
域名:turgidcat.space
站点目录:/var/www/turgidcat
部署产物:dist/
首次配置
mkdir -p /var/www/turgidcat
nano /etc/nginx/sites-available/turgidcat
ln -sf /etc/nginx/sites-available/turgidcat /etc/nginx/sites-enabled/turgidcat
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx `/etc/nginx/sites-available/turgidcat` 内容:
server {
listen 80;
listen [::]:80;
server_name turgidcat.space www.turgidcat.space;
root /var/www/turgidcat;
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-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 256;
} 日常更新
npm run build
scp -r dist/* root@YOUR_SERVER_IP:/var/www/turgidcat/
ssh root@YOUR_SERVER_IP "nginx -s reload" HTTPS
apt install certbot python3-certbot-nginx -y
certbot --nginx -d turgidcat.space -d www.turgidcat.space
certbot renew --dry-run 常见检查
DNS A 记录要指向服务器公网 IP。
阿里云安全组要放行 22 / 80 / 443。
如果上传后页面没变,先强刷浏览器,再检查 `/var/www/turgidcat/index.html` 时间戳。
如果出现 403,执行 `chown -R www-data:www-data /var/www/turgidcat && chmod -R 755 /var/www/turgidcat`。