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"; } }