From c38a4f0f627055861e9d6ecb2b69ec26a02326fa Mon Sep 17 00:00:00 2001 From: shenjianZ Date: Tue, 29 Jul 2025 08:39:20 +0800 Subject: [PATCH] feat: add docker compose full deploy --- compose.full.env | 12 +++++++++ docker-compose-full.yml | 57 +++++++++++++++++++++++++++++++++++++++++ nginx.full.conf | 30 ++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 compose.full.env create mode 100644 docker-compose-full.yml create mode 100644 nginx.full.conf diff --git a/compose.full.env b/compose.full.env new file mode 100644 index 0000000..1adcaf5 --- /dev/null +++ b/compose.full.env @@ -0,0 +1,12 @@ +# MySQL/MariaDB Settings +MYSQL_ROOT_PASSWORD=your_strong_root_password +MYSQL_DATABASE=maildb +MYSQL_USER=root +MYSQL_PASSWORD=root_password + +# Backend Database Settings +# These should match the MySQL/MariaDB settings above +DB_HOST=mysql +DB_USER=${MYSQL_USER} +DB_PASSWORD=${MYSQL_PASSWORD} +DB_NAME=${MYSQL_DATABASE} \ No newline at end of file diff --git a/docker-compose-full.yml b/docker-compose-full.yml new file mode 100644 index 0000000..f53973f --- /dev/null +++ b/docker-compose-full.yml @@ -0,0 +1,57 @@ +version: '3.3' + +services: + # 1. 后端服务 (Node.js + Express + SMTP Server) + backend: + build: ./backend + container_name: email-backend + restart: always + env_file: + - compose.full.env + networks: + - email-network + # 不直接暴露端口给外部,由 Nginx 统一代理 + # ports: + # - "5182:5182" + # - "25:25" + + # 2. 数据库服务 (MySQL) + mysql: + image: mysql:8.0 + container_name: email-mysql + restart: always + env_file: + - compose.full.env + volumes: + - mysql-data:/var/lib/mysql + networks: + - email-network + + # 3. Nginx 反向代理 + nginx: + image: nginx:latest + container_name: email-nginx + restart: always + ports: + - "7614:80" # HTTP + - "443:443" # HTTPS (需要SSL证书) + - "25:25" # SMTP 端口,转发给后端 + volumes: + # 挂载前端构建好的静态文件 + - ./frontend/dist:/usr/share/nginx/html + # 挂载 Nginx 配置文件 + - ./nginx.full.conf:/etc/nginx/nginx.conf:ro + # (可选) 挂载 SSL 证书 + # - ./certs:/etc/nginx/certs:ro + depends_on: + - backend + - mysql + networks: + - email-network + +networks: + email-network: + driver: bridge + +volumes: + mysql-data: {} \ No newline at end of file diff --git a/nginx.full.conf b/nginx.full.conf new file mode 100644 index 0000000..08a5f20 --- /dev/null +++ b/nginx.full.conf @@ -0,0 +1,30 @@ +events {} + +http { + server { + listen 7614; + + # 前端静态文件 + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + # 后端 API 转发 + location /api { + proxy_pass http://backend:5182; + 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; + } + } +} + +stream { + server { + listen 25; + proxy_pass backend:25; + } +}