# ============================================================ # AI Chat - 宝塔面板伪静态规则 # ============================================================ # # 使用方法: # 宝塔面板 → 网站 → 找到你的站点 → 设置 → 伪静态 # 将本文件内容完整粘贴到伪静态输入框中,保存即可 # # 前置条件: # - 网站根目录已指向 public/ 目录 # - PHP 8.0 已在宝塔中安装并启用 # - 如 PHP 版本非 8.0,需将下方 php-cgi-80 改为对应版本号 # # ============================================================ # 默认路由 location / { try_files $uri $uri/ /login.php; } # API 路由 — 将 /api/* 请求转发到 api.php 处理 location /api/ { try_files $uri /api.php$is_args$args; fastcgi_pass unix:/tmp/php-cgi-80.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/api.php; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param REQUEST_URI $request_uri; } # SSE 流式响应 — AI 对话需要禁用缓冲以实现实时输出 location /api/chat/completions { fastcgi_pass unix:/tmp/php-cgi-80.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/api.php; fastcgi_param REQUEST_URI $request_uri; fastcgi_buffering off; fastcgi_cache off; proxy_buffering off; add_header X-Accel-Buffering no; fastcgi_read_timeout 300s; } # 静态资源缓存 location /assets/ { expires 30d; add_header Cache-Control "public, immutable"; } # 上传文件缓存 location /uploads/ { expires 7d; add_header Cache-Control "public"; } # 禁止访问非公开目录 location ~ /(app|config|vendor|tests|scripts|\.cospec)/ { deny all; return 404; } # 禁止访问隐藏文件 location ~ /\. { deny all; return 404; }