21830d507d
P0 修复 — /itportal/ HTTP 500(连续 3+ 天阻塞)
根因分析:
- portal 源码 frontend-portal/ 在 commit bea288e4 (2026-07-11) 被误删
- portal dist 不存在(前端目录已不存在)
- backend/app/api/portal.py 也已删除
- /api/portal/* API 不再在 router.py 注册
- 但 nginx 配置 + docker-compose 仍引用 portal dist → try_files 指向空目录 → 500
- nginx-split.conf 还有根路径重定向 / → /itportal/ → 用户访问根域名直接 500
修复(最小集、最安全):
1. nginx 6 个配置(nginx/nginx.conf + 5 个 deploy-server 历史变体):
- 删除 location /itportal/ { alias ... } 静态块
- 保留 location /itportal/meetingroom/ API 块(最长前缀仍命中)
- nginx-split.conf / nginx-full.conf / nginx-green-upstream.conf 根重定向
/itportal/ → /itdesk/
2. docker-compose 4 个配置(+split):
- 删除 ./frontend-portal/dist 或 ./html/itportal 卷挂载
3. deploy-server/deploy.sh:
- 删除 portal dist 备份/解压步骤
- 部署完成提示去掉 /itportal/ 入口
预期效果:
- /itportal/ → nginx 404(不再 500)
- /itportal/meetingroom/ → API 仍工作(终端+H5 共用会议室预定)
- /itdesk/ /itagent/ /itadmin/ /itterminal/ 不受影响
- 根域名访问 → 重定向到 /itdesk/(H5 入口)
文件改动:
- nginx/nginx.conf(双 server block)
- deploy-server/nginx.conf(双 server block)
- deploy-server/nginx-full.conf + green-upstream.conf + nginx.conf + nginx-split.conf
- docker-compose.yml + 3 个 deploy-server 变体
- deploy-server/deploy.sh
⚠️ 待部署(无 jumpserver/VPN):本地已就绪,需在 jumpserver-V2 流程下
scp 上述 11 个文件到 /opt/wecom-it-desk/ 覆盖 + docker compose restart nginx 验证
验证命令:curl -I https://itsupport.servyou.com.cn/itportal/ 期望返回 404(或 301/302)
curl -I https://itsupport.servyou.com.cn/itportal/meetingroom/... 期望 200/401/403
curl -I https://itsupport.servyou.com.cn/ 期望 302 → /itdesk/
Refs: 滴答清单任务 6a6bfc29e4b06440c36701e1 (P0 逾期 1 天)
350 lines
16 KiB
Nginx Configuration File
350 lines
16 KiB
Nginx Configuration File
# =============================================================================
|
||
# 企微IT智能服务台 — Nginx 反向代理配置
|
||
# =============================================================================
|
||
# 部署说明:
|
||
# - 本 nginx 运行在 Docker 容器内,负责统一路由
|
||
# - 数据查询平台运行在**另一台主机**,通过 proxy_pass 转发
|
||
# - 修改 DATAQUERY_HOST 为数据平台实际 IP 地址
|
||
#
|
||
# 路由规则:
|
||
# /itdesk/ → H5 员工端静态文件
|
||
# /itagent/ → 坐席工作台静态文件
|
||
# /itadmin/ → 管理后台静态文件
|
||
# /itportal/ → 统一入口(角色选择)静态文件
|
||
# /itterminal/ → 小鱼终端大屏静态文件
|
||
# /itportal/meetingroom/ → 会议室API(终端+H5共用,代理到后端)
|
||
# /api/ → 后端 FastAPI(容器名 backend:8000)
|
||
# /ws/ → WebSocket(容器名 backend:8000,支持升级)
|
||
# / → IT 数据查询平台(远程主机)
|
||
# =============================================================================
|
||
|
||
events {
|
||
worker_connections 1024;
|
||
}
|
||
|
||
http {
|
||
include /etc/nginx/mime.types;
|
||
default_type application/octet-stream;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 日志格式
|
||
# ------------------------------------------------------------------
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
'$status $body_bytes_sent "$http_referer" '
|
||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||
|
||
access_log /var/log/nginx/access.log main;
|
||
error_log /var/log/nginx/error.log warn;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 基础配置
|
||
# ------------------------------------------------------------------
|
||
sendfile on;
|
||
tcp_nopush on;
|
||
tcp_nodelay on;
|
||
keepalive_timeout 65;
|
||
types_hash_max_size 2048;
|
||
client_max_body_size 50m; # 支持文件上传(企微媒体文件)
|
||
|
||
# ------------------------------------------------------------------
|
||
# Gzip 压缩(前端静态资源)
|
||
# ------------------------------------------------------------------
|
||
gzip on;
|
||
gzip_vary on;
|
||
gzip_min_length 1024;
|
||
gzip_types text/plain text/css text/xml text/javascript
|
||
application/javascript application/xml+rss
|
||
application/json application/ld+json;
|
||
|
||
# =================================================================
|
||
# 上游服务定义(Docker 内部网络)
|
||
# =================================================================
|
||
upstream backend_api {
|
||
server backend:8000;
|
||
}
|
||
|
||
# =================================================================
|
||
# HTTPS 服务:监听 443 端口(SSL)
|
||
# =================================================================
|
||
server {
|
||
listen 80;
|
||
listen 443 ssl;
|
||
server_name itsupport.servyou.com.cn;
|
||
|
||
# SSL 证书配置(使用通配符证书 *.servyou.com.cn)
|
||
ssl_certificate /etc/nginx/ssl/servyou.com.cn.crt;
|
||
ssl_certificate_key /etc/nginx/ssl/servyou.com.cn.key;
|
||
ssl_protocols TLSv1.2 TLSv1.3;
|
||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||
ssl_prefer_server_ciphers on;
|
||
ssl_session_cache shared:SSL:10m;
|
||
ssl_session_timeout 1d;
|
||
|
||
# ------------------------------------------------------------------
|
||
# H5 员工端 — /itdesk/
|
||
# ------------------------------------------------------------------
|
||
location /itdesk/ {
|
||
alias /usr/share/nginx/html/itdesk/;
|
||
index index.html;
|
||
try_files $uri /itdesk/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 坐席工作台 — /itagent/
|
||
# ------------------------------------------------------------------
|
||
location /itagent/ {
|
||
alias /usr/share/nginx/html/itagent/;
|
||
index index.html;
|
||
try_files $uri /itagent/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 管理后台 — /itadmin/
|
||
# ------------------------------------------------------------------
|
||
location /itadmin/ {
|
||
alias /usr/share/nginx/html/itadmin/;
|
||
index index.html;
|
||
try_files $uri /itadmin/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 小鱼终端大屏 — /itterminal/
|
||
# ------------------------------------------------------------------
|
||
location /itterminal/ {
|
||
alias /usr/share/nginx/html/itterminal/;
|
||
index index.html;
|
||
try_files $uri /itterminal/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 会议室 API — /itportal/meetingroom/
|
||
# 说明:终端和H5共用的会议室预定/报修/指南API
|
||
# 必须在 /itportal/ 静态文件之前匹配(nginx最长前缀优先)
|
||
# ------------------------------------------------------------------
|
||
location /itportal/meetingroom/ {
|
||
proxy_pass http://backend_api;
|
||
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;
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 300s;
|
||
proxy_read_timeout 300s;
|
||
}
|
||
# ⚠️ /itportal/ 静态前端块已移除 (2026-08-03 fix)
|
||
# 历史: portal 源码 frontend-portal/ 在 commit bea288e4 (2026-07-11) 已删除,
|
||
# dist 目录不存在, alias 指向空目录导致 try_files 全部 500。
|
||
# /itportal/ 现在返回 nginx 404(最长前缀 /itportal/meetingroom/ 仍工作)。
|
||
# 关联 issue: 滴答清单任务 6a6bfc29e4b06440c36701e1 (P0)
|
||
|
||
# ------------------------------------------------------------------
|
||
# 后端 API — /api/
|
||
# ------------------------------------------------------------------
|
||
location /api/ {
|
||
proxy_pass http://backend_api/;
|
||
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;
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 300s;
|
||
proxy_read_timeout 300s;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# H5 用户端 — /h5/
|
||
# 说明:H5 是静态前端应用,必须配置为静态文件服务(alias)!
|
||
# ⚠️ 禁止改为 proxy_pass,否则返回 404(后端无 /h5/ 路由)
|
||
# 关联 CASE:CASE-20260714-02 / CASE-20260716-01
|
||
# ------------------------------------------------------------------
|
||
location /h5/ {
|
||
alias /usr/share/nginx/html/h5/;
|
||
index index.html;
|
||
try_files $uri /h5/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 静态媒体文件 — /media/ (企微下载的图片/H5上传的文件)
|
||
# 代理到后端 /api/media/ 接口(容器内路径 /app/uploads/)
|
||
# ------------------------------------------------------------------
|
||
location /media/ {
|
||
proxy_pass http://backend_api/media/;
|
||
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;
|
||
expires 30d;
|
||
add_header Cache-Control "public, immutable";
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# WebSocket — /ws/
|
||
# ------------------------------------------------------------------
|
||
location /ws/ {
|
||
proxy_pass http://backend_api;
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
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_read_timeout 86400s;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# IT 数据查询平台 — /(根路径,反代到远程主机)
|
||
# ------------------------------------------------------------------
|
||
location / {
|
||
proxy_pass http://10.80.0.130:8080;
|
||
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;
|
||
proxy_connect_timeout 30s;
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 60s;
|
||
}
|
||
}
|
||
|
||
# =================================================================
|
||
# 备用:监听 80 端口(开发调试用)
|
||
# =================================================================
|
||
server {
|
||
listen 80;
|
||
server_name localhost;
|
||
|
||
# ------------------------------------------------------------------
|
||
# 健康检查端点(用于 Docker healthcheck)
|
||
# ------------------------------------------------------------------
|
||
location = /itdesk/health {
|
||
access_log off;
|
||
return 200 "healthy\n";
|
||
add_header Content-Type text/plain;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# H5 员工端 — /itdesk/
|
||
# ------------------------------------------------------------------
|
||
# 注意:alias + try_files $uri/ 会导致 301 重定向死循环,
|
||
# 移除 $uri/ 避免触发 nginx 的目录重定向行为
|
||
location /itdesk/ {
|
||
alias /usr/share/nginx/html/itdesk/;
|
||
index index.html;
|
||
try_files $uri /itdesk/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 坐席工作台 — /itagent/
|
||
# ------------------------------------------------------------------
|
||
location /itagent/ {
|
||
alias /usr/share/nginx/html/itagent/;
|
||
index index.html;
|
||
try_files $uri /itagent/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 管理后台 — /itadmin/
|
||
# ------------------------------------------------------------------
|
||
location /itadmin/ {
|
||
alias /usr/share/nginx/html/itadmin/;
|
||
index index.html;
|
||
try_files $uri /itadmin/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 小鱼终端大屏 — /itterminal/
|
||
# ------------------------------------------------------------------
|
||
location /itterminal/ {
|
||
alias /usr/share/nginx/html/itterminal/;
|
||
index index.html;
|
||
try_files $uri /itterminal/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# 会议室 API — /itportal/meetingroom/
|
||
# 说明:终端和H5共用的会议室预定/报修/指南API
|
||
# 必须在 /itportal/ 静态文件之前匹配(nginx最长前缀优先)
|
||
# ------------------------------------------------------------------
|
||
location /itportal/meetingroom/ {
|
||
proxy_pass http://backend_api;
|
||
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;
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 300s;
|
||
proxy_read_timeout 300s;
|
||
}
|
||
# ⚠️ /itportal/ 静态前端块已移除 (2026-08-03 fix)
|
||
# 历史: portal 源码 frontend-portal/ 在 commit bea288e4 (2026-07-11) 已删除,
|
||
# dist 目录不存在, alias 指向空目录导致 try_files 全部 500。
|
||
# /itportal/ 现在返回 nginx 404(最长前缀 /itportal/meetingroom/ 仍工作)。
|
||
# 关联 issue: 滴答清单任务 6a6bfc29e4b06440c36701e1 (P0)
|
||
|
||
# ------------------------------------------------------------------
|
||
# 后端 API — /api/
|
||
# ------------------------------------------------------------------
|
||
location /api/ {
|
||
proxy_pass http://backend_api/;
|
||
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;
|
||
|
||
# 超时设置(AI 回复可能较慢)
|
||
proxy_connect_timeout 60s;
|
||
proxy_send_timeout 300s;
|
||
proxy_read_timeout 300s;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# H5 用户端 — /h5/
|
||
# 说明:H5 是静态前端应用,必须配置为静态文件服务(alias)!
|
||
# ⚠️ 禁止改为 proxy_pass,否则返回 404(后端无 /h5/ 路由)
|
||
# 关联 CASE:CASE-20260714-02 / CASE-20260716-01
|
||
# ------------------------------------------------------------------
|
||
location /h5/ {
|
||
alias /usr/share/nginx/html/h5/;
|
||
index index.html;
|
||
try_files $uri /h5/index.html;
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# WebSocket — /ws/(坐席端实时通信)
|
||
# ------------------------------------------------------------------
|
||
location /ws/ {
|
||
proxy_pass http://backend_api;
|
||
proxy_http_version 1.1;
|
||
proxy_set_header Upgrade $http_upgrade;
|
||
proxy_set_header Connection "upgrade";
|
||
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_read_timeout 86400s; # WebSocket 长连接
|
||
}
|
||
|
||
# ------------------------------------------------------------------
|
||
# IT 数据查询平台 — /(根路径,反代到远程主机)
|
||
# ------------------------------------------------------------------
|
||
# 说明:数据查询平台部署在另一台主机,
|
||
# 通过 Nginx 反代实现同一域名下访问。
|
||
# 修改 $dataquery_host 为实际 IP。
|
||
# ------------------------------------------------------------------
|
||
location / {
|
||
# 数据平台远程主机(修改为实际 IP)
|
||
# 方式1:在 /etc/nginx/nginx.conf 同目录放 env 文件
|
||
# 方式2:docker-compose.yml 中通过 command 覆盖
|
||
proxy_pass http://10.80.0.130:8080; # ← 修改为数据平台实际 IP:端口
|
||
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;
|
||
|
||
# 超时设置
|
||
proxy_connect_timeout 30s;
|
||
proxy_send_timeout 60s;
|
||
proxy_read_timeout 60s;
|
||
}
|
||
}
|
||
}
|