6.1 KiB
6.1 KiB
FLNXI官网 - 部署指南
📋 部署前准备
系统要求
- 操作系统: Linux (推荐 Ubuntu 20.04+) / macOS / Windows
- Docker: 20.10+
- Docker Compose: 1.29+
- 内存: 至少2GB可用内存
- 磁盘: 至少5GB可用空间
- 网络: 稳定的互联网连接
🐳 Docker部署(推荐)
方式一:使用Docker Compose(最简单)
1. 克隆项目
git clone <repository-url>
cd xiaso
2. 启动服务
docker-compose up -d
3. 检查状态
# 查看容器状态
docker-compose ps
# 查看日志
docker-compose logs -f
4. 访问网站
打开浏览器访问: http://localhost:3000
5. 停止服务
docker-compose down
方式二:使用Docker命令
1. 构建镜像
docker build -t flnxi-website:latest .
2. 运行容器
docker run -d \
--name flnxi-website \
-p 3000:3000 \
--restart unless-stopped \
flnxi-website:latest
3. 查看日志
docker logs -f flnxi-website
4. 停止容器
docker stop flnxi-website
docker rm flnxi-website
💻 本地开发部署
1. 安装依赖
# 使用 npm
npm install
# 使用 yarn
yarn install
# 使用 pnpm
pnpm install
2. 开发模式运行
npm run dev
访问 http://localhost:3000
3. 生产构建
# 构建
npm run build
# 启动生产服务器
npm start
☁️ 服务器部署
使用 Nginx 反向代理
1. 部署Docker容器
docker-compose up -d
2. 配置Nginx
创建 /etc/nginx/sites-available/flnxi 文件:
server {
listen 80;
server_name flnxi.com www.flnxi.com;
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;
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;
}
}
3. 启用站点
sudo ln -s /etc/nginx/sites-available/flnxi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
4. 配置SSL (可选但推荐)
使用 Let's Encrypt:
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d flnxi.com -d www.flnxi.com
🔄 更新部署
Docker Compose 方式
# 拉取最新代码
git pull origin main
# 重新构建并启动
docker-compose up -d --build
# 清理旧镜像
docker image prune -f
Docker 命令方式
# 停止旧容器
docker stop flnxi-website
docker rm flnxi-website
# 重新构建
docker build -t flnxi-website:latest .
# 启动新容器
docker run -d \
--name flnxi-website \
-p 3000:3000 \
--restart unless-stopped \
flnxi-website:latest
🔍 健康检查
检查容器状态
docker ps | grep flnxi-website
检查日志
docker logs --tail 100 -f flnxi-website
测试网站响应
curl http://localhost:3000
Docker健康检查
docker inspect --format='{{.State.Health.Status}}' flnxi-website
🛠️ 故障排查
问题1: 容器启动失败
检查日志:
docker logs flnxi-website
常见原因:
- 端口3000已被占用
- 内存不足
- 镜像构建失败
解决方案:
# 检查端口占用
lsof -i :3000
# 使用其他端口
docker run -p 8080:3000 flnxi-website:latest
问题2: 网站无法访问
检查容器运行状态:
docker ps -a | grep flnxi
检查网络连接:
docker inspect flnxi-website | grep IPAddress
curl http://<container-ip>:3000
检查防火墙:
sudo ufw status
sudo ufw allow 3000
问题3: 构建失败
清理Docker缓存:
docker system prune -a
docker builder prune -a
重新构建:
docker build --no-cache -t flnxi-website:latest .
📊 性能优化
1. 使用CDN
建议将静态资源部署到CDN,修改 next.config.js:
const nextConfig = {
assetPrefix: 'https://cdn.flnxi.com',
// ...
}
2. 启用Gzip压缩
Nginx配置:
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json;
3. 配置缓存
location /_next/static {
proxy_cache_valid 200 365d;
proxy_pass http://localhost:3000;
}
🔐 安全建议
1. 限制访问
# 限制访问频率
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
limit_req zone=one burst=20 nodelay;
2. 隐藏服务器信息
server_tokens off;
3. 添加安全头
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
📈 监控方案
使用Docker Stats
docker stats flnxi-website
日志监控
# 实时日志
docker logs -f flnxi-website
# 最近日志
docker logs --tail 100 flnxi-website
自动重启
docker update --restart unless-stopped flnxi-website
🗂️ 备份方案
备份镜像
docker save flnxi-website:latest | gzip > flnxi-backup-$(date +%Y%m%d).tar.gz
恢复镜像
docker load < flnxi-backup-20250126.tar.gz
📞 技术支持
如遇到部署问题,请联系:
- 📧 Email: tech@flnxi.com
- 💬 微信: 扫码添加技术支持
- 🌐 文档: https://docs.flnxi.com
✅ 部署检查清单
- Docker和Docker Compose已安装
- 端口3000可用
- 服务器有足够的内存和磁盘空间
- 防火墙规则已配置
- 域名DNS已解析
- SSL证书已配置
- Nginx反向代理已配置
- 容器自动重启已启用
- 监控和日志已配置
- 备份策略已制定
更新日期: 2025-10-26
版本: 1.0.0