-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-server.bat
More file actions
60 lines (52 loc) · 2.01 KB
/
Copy pathdeploy-server.bat
File metadata and controls
60 lines (52 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@echo off
echo 开始部署到服务器...
REM 连接到服务器并执行部署命令
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "cd /var/www/portfolio && npx next build"
echo 构建完成,继续配置PM2...
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "cd /var/www/portfolio && cat > ecosystem.config.js << 'EOF'
module.exports = {
apps: [{
name: 'portfolio-website',
script: 'npm',
args: 'start',
cwd: '/var/www/portfolio',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
}
EOF"
echo 启动PM2应用...
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "cd /var/www/portfolio && pm2 start ecosystem.config.js && pm2 save && pm2 startup"
echo 配置nginx...
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "tee /etc/nginx/sites-available/portfolio << 'EOF'
server {
listen 80;
server_name _;
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_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_cache_bypass \$http_upgrade;
}
}
EOF"
echo 启用nginx站点...
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "ln -sf /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled/ && rm -f /etc/nginx/sites-enabled/default && nginx -t && systemctl restart nginx"
echo 配置防火墙...
echo Jiangsheng520@ | ssh -o StrictHostKeyChecking=no root@47.92.140.204 "ufw allow 22 && ufw allow 80 && ufw allow 443 && ufw --force enable"
echo 部署完成!
echo 网站地址: http://47.92.140.204
echo 查看状态: pm2 status
echo 查看日志: pm2 logs portfolio-website
pause