From 552bfe7e7a9ce05dd5df13e9241e3e2abd5f8b5b Mon Sep 17 00:00:00 2001 From: wangyang Date: Fri, 15 May 2026 18:26:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=20Nginx=20=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Slim=20base=20path=20=E5=AF=BC=E8=87=B4=20?= =?UTF-8?q?API=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 显式设置 SCRIPT_NAME 为 /index.php,避免 PHP-FPM 推断为 /api/index.php - 否则 Slim 4 认为 base path 是 /api,路由 /api/conversations 匹配失败 2026-05-15 --- nginx.conf | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..bdb486f --- /dev/null +++ b/nginx.conf @@ -0,0 +1,43 @@ +server { + listen 80; + server_name localhost; + + # 前端静态文件 + root /var/www/dist; + index index.html; + + # 文件上传限制 + client_max_body_size 50M; + + # API 路由 → PHP-FPM + location /api/ { + fastcgi_pass chat-php:9000; + fastcgi_index index.php; + include fastcgi_params; + + # 关键:硬编码 PHP 入口,让 Slim 正确解析路由 + fastcgi_param SCRIPT_FILENAME /var/www/html/public/index.php; + + # 关键:显式设置 SCRIPT_NAME 为空 base path + # 否则 PHP-FPM 会推断为 /api/index.php,导致 Slim 路由匹配失败 + fastcgi_param SCRIPT_NAME /index.php; + + fastcgi_read_timeout 300; + + # HTTPS 反向代理头 + fastcgi_param HTTPS on; + fastcgi_param HTTP_X_FORWARDED_PROTO https; + fastcgi_param HTTP_X_FORWARDED_HOST www.eryang.wang; + } + + # SPA 路由回退:所有非 API 请求返回 index.html + location / { + try_files $uri $uri/ /index.html; + } + + # 静态资源缓存 + location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ { + expires 1M; + add_header Cache-Control "public, immutable"; + } +}