# 懂云项目部署指南 ## 📋 目录 - [静态导出部署](#静态导出部署) - [Docker部署](#docker部署) - [云服务器部署](#云服务器部署) - [域名和SSL配置](#域名和ssl配置) - [性能优化](#性能优化) ## 🚀 静态导出部署 ### 1. 本地构建 ```bash # 构建静态文件 npm run build:static # 或使用部署脚本 chmod +x deploy.sh ./deploy.sh production ``` ### 2. 上传到服务器 ```bash # 方案1:使用rsync(推荐) rsync -avz --delete out/ user@your-server:/var/www/html/ # 方案2:使用scp scp -r out/* user@your-server:/var/www/html/ # 方案3:打包上传 tar -czf dongyun-static.tar.gz out scp dongyun-static.tar.gz user@your-server:~/ ssh user@your-server "cd /var/www/html && tar -xzf ~/dongyun-static.tar.gz --strip-components=1" ``` ## 🐳 Docker部署 ### 1. 使用Docker Compose(推荐) ```bash # 构建并启动 docker-compose up -d --build # 查看日志 docker-compose logs -f # 停止服务 docker-compose down ``` ### 2. 使用单独的Docker命令 ```bash # 构建镜像 docker build -t dongyun-static . # 运行容器 docker run -d \ --name dongyun-web \ -p 80:80 \ -v $(pwd)/logs:/var/log/nginx \ --restart unless-stopped \ dongyun-static # 查看运行状态 docker ps docker logs dongyun-web ``` ## ☁️ 云服务器部署 ### 阿里云ECS部署 ```bash # 1. 连接服务器 ssh root@your-aliyun-server # 2. 安装Docker curl -fsSL https://get.docker.com | bash systemctl start docker systemctl enable docker # 3. 上传项目文件 scp -r ./* root@your-aliyun-server:~/dongyun/ # 4. 在服务器上构建部署 cd ~/dongyun docker-compose up -d --build ``` ### 腾讯云CVM部署 ```bash # 1. 安装Nginx sudo apt update sudo apt install nginx -y # 2. 上传静态文件 rsync -avz out/ root@your-tencent-server:/var/www/html/ # 3. 配置Nginx sudo cp nginx.conf /etc/nginx/nginx.conf sudo nginx -t sudo systemctl reload nginx ``` ### AWS EC2部署 ```bash # 1. 使用Amazon Linux 2 sudo yum update -y sudo amazon-linux-extras install docker -y sudo service docker start sudo usermod -a -G docker ec2-user # 2. 安装Docker Compose sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # 3. 部署项目 git clone your-repo cd dongyun docker-compose up -d --build ``` ## 🌐 域名和SSL配置 ### 1. 域名解析 ``` A记录: @ -> 你的服务器IP A记录: www -> 你的服务器IP ``` ### 2. 免费SSL证书(Let's Encrypt) ```bash # 安装certbot sudo apt install certbot python3-certbot-nginx -y # 申请证书 sudo certbot --nginx -d your-domain.com -d www.your-domain.com # 自动续期 sudo crontab -e # 添加:0 12 * * * /usr/bin/certbot renew --quiet ``` ### 3. Nginx HTTPS配置 ```nginx server { listen 443 ssl http2; server_name your-domain.com www.your-domain.com; ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; # SSL配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; # 其他配置... } # HTTP重定向到HTTPS server { listen 80; server_name your-domain.com www.your-domain.com; return 301 https://$server_name$request_uri; } ``` ## ⚡ 性能优化 ### 1. CDN配置 ```bash # 阿里云CDN # 1. 开通CDN服务 # 2. 添加加速域名 # 3. 配置源站 # 4. 配置缓存规则 # 腾讯云CDN # 1. 登录腾讯云控制台 # 2. 开通CDN服务 # 3. 添加域名 # 4. 配置CNAME ``` ### 2. 服务器优化 ```bash # 1. 调整Nginx worker进程数 worker_processes auto; # 2. 优化文件描述符限制 echo "* soft nofile 65535" >> /etc/security/limits.conf echo "* hard nofile 65535" >> /etc/security/limits.conf # 3. 启用HTTP/2 # 在nginx配置中添加 http2 listen 443 ssl http2; ``` ### 3. 监控设置 ```bash # 安装监控工具 sudo apt install htop iotop nethogs -y # 设置日志轮转 sudo logrotate -d /etc/logrotate.d/nginx # 监控脚本 cat > monitor.sh << 'EOF' #!/bin/bash # 检查网站可用性 curl -f http://your-domain.com/ > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "网站不可访问,请检查服务状态" | mail -s "网站告警" admin@your-domain.com fi EOF # 添加到crontab echo "*/5 * * * * /path/to/monitor.sh" | crontab - ``` ## 🔧 常用命令 ### Docker相关 ```bash # 查看容器状态 docker ps -a # 查看日志 docker logs -f dongyun-web # 进入容器 docker exec -it dongyun-web sh # 重启容器 docker restart dongyun-web # 更新部署 docker-compose down docker-compose up -d --build ``` ### Nginx相关 ```bash # 检查配置 sudo nginx -t # 重载配置 sudo nginx -s reload # 重启服务 sudo systemctl restart nginx # 查看状态 sudo systemctl status nginx # 查看日志 sudo tail -f /var/log/nginx/access.log sudo tail -f /var/log/nginx/error.log ``` ## 🚨 故障排除 ### 1. 网站无法访问 ```bash # 检查端口是否开放 netstat -tlnp | grep :80 netstat -tlnp | grep :443 # 检查防火墙 sudo ufw status sudo firewall-cmd --list-all # 检查DNS解析 nslookup your-domain.com dig your-domain.com ``` ### 2. SSL证书问题 ```bash # 检查证书有效期 openssl x509 -in /etc/letsencrypt/live/your-domain.com/cert.pem -text -noout # 手动续期 sudo certbot renew --dry-run # 查看证书状态 sudo certbot certificates ``` ### 3. 性能问题 ```bash # 查看服务器负载 top htop uptime # 查看磁盘使用 df -h du -sh /var/www/html/ # 查看内存使用 free -h ``` ## 📞 技术支持 如果在部署过程中遇到问题,可以: 1. 查看项目日志文件 2. 检查服务器系统日志 3. 联系技术支持团队 --- **部署完成后记得:** - ✅ 测试网站所有功能 - ✅ 配置SSL证书 - ✅ 设置CDN加速 - ✅ 配置网站监控 - ✅ 备份重要数据