完善docker配置

This commit is contained in:
小贺
2025-09-02 22:41:02 +08:00
parent 8de03156e1
commit 6b5603df84
10 changed files with 121 additions and 1 deletions

26
app/docker-compose.yml Normal file
View File

@@ -0,0 +1,26 @@
version: '3.8'
services:
frontend:
build:
context: ./front
dockerfile: dockerfile
ports:
- "80:80"
depends_on:
- backend
networks:
- app-network
backend:
build:
context: ./backend
dockerfile: dockerfile
ports:
- "5000:5000"
networks:
- app-network
networks:
app-network:
driver: bridge

31
app/front/nginx.conf Normal file
View File

@@ -0,0 +1,31 @@
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 配置前端路由支持SPA单页应用
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# 处理静态文件
location / {
try_files $uri $uri/ /index.html;
}
# 代理API请求到后端
location /api/ {
proxy_pass http://backend:5000/;
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;
}
}
}