06488f0237
功能: - Go后端 (Gin + GORM + PostgreSQL) - UniApp用户端 (iOS/Android/小程序) - DaisyUI5后台管理 - JWT认证 + 微信登录 - 盲选加权算法 - 会员系统 + 优惠券 - 打分评价 + 偏好学习
3.8 KiB
3.8 KiB
部署指南
服务器要求
- Ubuntu 20.04+
- 2GB+ RAM
- Docker & Docker Compose
- PostgreSQL 13+ (或使用 Docker)
- Nginx (可选,用于反向代理)
1. 数据库准备
# 创建数据库
sudo -u postgres psql
CREATE DATABASE blind_select;
CREATE USER blind_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE blind_select TO blind_user;
# 运行迁移
psql -U blind_user -d blind_select < migrations/001_init.sql
2. 后端部署
方式一:直接运行
cd backend
# 构建
go build -o blind-server cmd/server/main.go
# 配置
cp config.yaml.example config.yaml
vim config.yaml
# 使用 systemd 运行
sudo cat > /etc/systemd/system/blind-server.service << EOF
[Unit]
Description=Blind Select Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/blind-select/backend
ExecStart=/opt/blind-select/backend/blind-server
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable blind-server
sudo systemctl start blind-server
方式二:Docker
cd backend
docker-compose up -d
3. UniApp 小程序部署
微信小程序
cd frontend-app
# 修改 manifest.json 中的 appid
# 修改 api/index.js 中的 BASE_URL 为你的 HTTPS 域名
# 构建
npm run build:mp-weixin
# 使用微信开发者工具上传
# 或使用脚本部署
./wechat-deploy.sh
小程序注意事项
- 域名必须是 HTTPS
- 需要在微信公众平台配置服务器域名
- 需要配置业务域名
4. 后台管理部署
cd frontend-admin
# 修改 API 地址
vim src/api/index.js
# 构建
npm run build
# Nginx 配置
server {
listen 80;
server_name admin.yourdomain.com;
root /opt/blind-select/frontend-admin/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
5. Nginx 配置 (可选)
# 后端 API
server {
listen 443 ssl;
server_name api.yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 后台管理
server {
listen 443 ssl;
server_name admin.yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
root /opt/blind-select/frontend-admin/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:8080;
}
}
6. 微信支付配置
- 在微信支付商户平台申请支付功能
- 配置支付回调域名
- 在后端配置支付密钥
# config.yaml 添加
wechat_pay:
mchid: your_mchid
serial_no: your_serial_no
private_key: /path/to/private_key.pem
api_v3_key: your_api_v3_key
7. 监控与日志
# 查看后端日志
journalctl -u blind-server -f
# Docker 日志
docker logs blind-server -f
8. 备份
# 数据库备份
pg_dump -U blind_user blind_select > backup_$(date +%Y%m%d).sql
# 定时备份 (crontab)
0 2 * * * pg_dump -U blind_user blind_select > /backup/blind_$(date +\%Y\%m\%d).sql
常见问题
Q: 小程序请求失败?
A: 检查服务器域名是否配置 HTTPS,是否在微信公众平台白名单
Q: 支付失败?
A: 检查微信支付证书配置,确保证书路径正确
Q: 盲选算法不准确?
A: 需要积累用户行为数据,初期可手动调整权重参数