From 24790d8e6965f7ce6c016d54a75ca77ff28cd1ba Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 11 May 2026 22:28:08 +0800 Subject: [PATCH] feat: add nginx router config file for backend and frontend --- backend/config.cfg.template | 14 ------- tools/.nginx.conf | 61 ++++++++++++++++++++++++++++ {scripts => tools}/dial_plate_gen.py | 0 3 files changed, 61 insertions(+), 14 deletions(-) delete mode 100644 backend/config.cfg.template create mode 100644 tools/.nginx.conf rename {scripts => tools}/dial_plate_gen.py (100%) diff --git a/backend/config.cfg.template b/backend/config.cfg.template deleted file mode 100644 index bc759cb..0000000 --- a/backend/config.cfg.template +++ /dev/null @@ -1,14 +0,0 @@ -{ - "database-type": "sqlite", - "database-config": { - "user": "", - "password": "", - "db": "", - "url": "", - "port": 3306 - }, - "web": { - "port": 8888 - }, - "debug": true -} \ No newline at end of file diff --git a/tools/.nginx.conf b/tools/.nginx.conf new file mode 100644 index 0000000..38148f6 --- /dev/null +++ b/tools/.nginx.conf @@ -0,0 +1,61 @@ +# ============================ +# 路由 1: /web -> 静态文件 +# ============================ +location /web { + # 使用 alias 精确映射 + # 请求 /web/index.html -> /var/www/static/index.html + alias /var/www/static; + + # 静态文件优化 + expires 7d; + add_header Cache-Control "public, max-age=604800"; + + # 尝试返回文件,不存在则返回404(避免落入其他location) + try_files $uri $uri/ =404; + + # 可选:启用 gzip 压缩 + gzip_static on; +} + +# ============================ +# 路由 2: /api -> Go 程序 (8848端口) +# ============================ +location /api { + # 反向代理到本地 Go 服务 + proxy_pass http://127.0.0.1:8848; + + # 重要:保留原始请求头 + 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; + + # WebSocket 支持(如果 Go 程序需要) + # proxy_http_version 1.1; + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection "upgrade"; + + # 超时设置(根据业务调整) + proxy_connect_timeout 60s; + proxy_send_timeout 60s; + proxy_read_timeout 60s; + + # 缓冲设置(可选,大文件上传时注意调整) + proxy_buffering on; + proxy_buffer_size 4k; + proxy_buffers 8 4k; +} + +# ============================ +# 可选:根路径处理 +# ============================ +location = / { + # 重定向到 /web + return 302 /web/; +} + +# 禁止访问隐藏文件 +location ~ /\. { + deny all; + return 404; +} \ No newline at end of file diff --git a/scripts/dial_plate_gen.py b/tools/dial_plate_gen.py similarity index 100% rename from scripts/dial_plate_gen.py rename to tools/dial_plate_gen.py