feat: add nginx router config file for backend and frontend
This commit is contained in:
61
tools/.nginx.conf
Normal file
61
tools/.nginx.conf
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user