用户指南应用部署
传统部署
在 VPS 服务器上传统部署
传统部署适合需要完全控制服务器的场景。
前置条件
- Linux 服务器(Ubuntu 22.04 推荐)
- Node.js >= 22.20.0
- PNPM >= 9.0.0
- PostgreSQL >= 13
- Nginx(反向代理)
- PM2(进程管理)
部署步骤
1. 安装依赖
# 安装 Node.js
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# 安装 PNPM
npm install -g pnpm
# 安装 PM2
npm install -g pm22. 克隆项目
cd /var/www
git clone https://github.com/your/tinyship.git
cd tinyship3. 安装依赖和构建
pnpm install
pnpm run build:next # 或 pnpm run build:nuxt4. 配置环境变量
cp env.example .env
nano .env # 编辑生产环境变量5. 初始化数据库
pnpm run db:push
pnpm run db:seed # 可选6. 使用 PM2 启动
# 启动 Next.js 应用
pm2 start npm --name "tinyship" -- run start:next
# 保存进程列表
pm2 save
# 设置开机自启
pm2 startupNginx 配置
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/ssl/certs/your-cert.pem;
ssl_certificate_key /etc/ssl/private/your-key.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}常用命令
# 查看应用状态
pm2 status
# 查看日志
pm2 logs tinyship
# 重启应用
pm2 restart tinyship
# 更新代码并重启
git pull && pnpm install && pnpm run build:next && pm2 restart tinyship自动化部署
考虑使用 CI/CD 工具(如 GitHub Actions)实现自动化部署。