测试部署-1
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# 生产部署说明
|
||||
|
||||
目标访问地址:
|
||||
|
||||
```text
|
||||
http://hfb.221329.cc.cd:7890
|
||||
```
|
||||
|
||||
生产部署只暴露宿主机 `7890` 端口,避免和服务器已有的 `80`、`443` 服务冲突。后端、MySQL、Redis、MinIO 均通过 Docker 内网通信。
|
||||
|
||||
## 1. 准备环境变量
|
||||
|
||||
```bash
|
||||
cp backend/.env.prod.example backend/.env
|
||||
```
|
||||
|
||||
编辑 `backend/.env`,至少替换以下占位值:
|
||||
|
||||
```text
|
||||
MYSQL_ROOT_PASSWORD
|
||||
MYSQL_PASSWORD
|
||||
MYSQL_DSN
|
||||
JWT_SECRET
|
||||
MINIO_ROOT_USER
|
||||
MINIO_ROOT_PASSWORD
|
||||
STORAGE_ACCESS_KEY_ID
|
||||
STORAGE_SECRET_ACCESS_KEY
|
||||
```
|
||||
|
||||
如果正式对外运营,还需要配置真实短信和实名服务,避免继续使用测试配置。
|
||||
|
||||
## 2. 启动服务
|
||||
|
||||
```bash
|
||||
docker compose -f deploy/docker-compose.prod.yml up -d --build
|
||||
```
|
||||
|
||||
## 3. 首次初始化数据库
|
||||
|
||||
将命令中的 `change-hfb-password` 替换为 `backend/.env` 里的 `MYSQL_PASSWORD`。
|
||||
|
||||
```bash
|
||||
for file in backend/migrations/*.sql; do
|
||||
docker compose -f deploy/docker-compose.prod.yml exec -T mysql \
|
||||
mysql -uhfb -pchange-hfb-password hfb_sys < "$file"
|
||||
done
|
||||
```
|
||||
|
||||
## 4. 验证
|
||||
|
||||
```bash
|
||||
curl http://127.0.0.1:7890/health
|
||||
curl http://127.0.0.1:7890/api/health
|
||||
```
|
||||
|
||||
浏览器访问:
|
||||
|
||||
```text
|
||||
http://hfb.221329.cc.cd:7890
|
||||
http://hfb.221329.cc.cd:7890/admin/login
|
||||
```
|
||||
|
||||
服务器安全组或防火墙需要放行 `7890/tcp`。
|
||||
@@ -1,12 +1,61 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.4
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ../backend/.env
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p\"$${MYSQL_ROOT_PASSWORD}\""]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
redis:
|
||||
image: redis:7.4-alpine
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
minio:
|
||||
image: minio/minio:RELEASE.2025-09-07T16-13-09Z
|
||||
restart: unless-stopped
|
||||
command: server /data --console-address ":9001"
|
||||
env_file:
|
||||
- ../backend/.env
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "mc", "ready", "local"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ../backend
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ../backend/.env
|
||||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_healthy
|
||||
expose:
|
||||
- "8080"
|
||||
|
||||
frontend:
|
||||
build:
|
||||
@@ -16,4 +65,9 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "80:80"
|
||||
- "7890:80"
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
redis_data:
|
||||
minio_data:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
server_name hfb.221329.cc.cd;
|
||||
|
||||
client_max_body_size 20m;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
@@ -11,14 +13,18 @@ server {
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8080/api/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_set_header Host $http_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_set_header X-Forwarded-Host $http_host;
|
||||
}
|
||||
|
||||
location /health {
|
||||
proxy_pass http://backend:8080/health;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Host $http_host;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user