v1.2修复优化
This commit is contained in:
@@ -1,35 +1,24 @@
|
||||
# ============================================================
|
||||
# AI Chat 宝塔面板 Nginx 配置片段(PHP-FPM 版本)
|
||||
# AI Chat - 宝塔面板伪静态规则
|
||||
# ============================================================
|
||||
#
|
||||
# 【使用说明】
|
||||
# 1. 本文件为宝塔面板专用的 Nginx 配置片段,不是完整的站点配置文件。
|
||||
# 2. 使用步骤:
|
||||
# a. 在宝塔面板中创建网站,PHP 版本选择 PHP 8.0
|
||||
# b. 将网站根目录指向 /path/to/ai-chat/public
|
||||
# c. 登录宝塔面板 → 网站 → 找到你的站点 → 点击"设置"
|
||||
# d. 在左侧菜单选择"配置文件"
|
||||
# e. 将下方"配置内容开始"到"配置内容结束"之间的内容,
|
||||
# 复制并粘贴到 server { } 块内(注意不要重复嵌套 server 块)
|
||||
# f. 保存即可生效
|
||||
# 3. 前置准备:
|
||||
# - 在宝塔面板中安装 PHP 8.0 并启用
|
||||
# - 安装 MySQL 5.7+ 或 8.0
|
||||
# - 安装 Composer
|
||||
# - 运行 composer install 安装 PHP 依赖
|
||||
# 使用方法:
|
||||
# 宝塔面板 → 网站 → 找到你的站点 → 设置 → 伪静态
|
||||
# 将本文件内容完整粘贴到伪静态输入框中,保存即可
|
||||
#
|
||||
# 前置条件:
|
||||
# - 网站根目录已指向 public/ 目录
|
||||
# - PHP 8.0 已在宝塔中安装并启用
|
||||
# - 如 PHP 版本非 8.0,需将下方 php-cgi-80 改为对应版本号
|
||||
#
|
||||
# ============================================================
|
||||
|
||||
# ↓↓↓ 配置内容开始 ↓↓↓
|
||||
|
||||
# === AI Chat 网站配置(PHP-FPM) ===
|
||||
|
||||
# 1. 默认路由
|
||||
# 默认路由
|
||||
location / {
|
||||
try_files $uri $uri/ /login.php;
|
||||
}
|
||||
|
||||
# 2. API 路由 - 转发到 api.php
|
||||
# API 路由 — 将 /api/* 请求转发到 api.php 处理
|
||||
location /api/ {
|
||||
try_files $uri /api.php$is_args$args;
|
||||
fastcgi_pass unix:/tmp/php-cgi-80.sock;
|
||||
@@ -40,47 +29,39 @@ location /api/ {
|
||||
fastcgi_param REQUEST_URI $request_uri;
|
||||
}
|
||||
|
||||
# 3. SSE 流式响应特殊配置(AI对话需要)
|
||||
# 针对 Chat API 的 SSE(Server-Sent Events)流式响应,
|
||||
# 需要禁用所有缓冲以确保实时输出
|
||||
# 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;
|
||||
# SSE 关键配置
|
||||
fastcgi_buffering off;
|
||||
fastcgi_cache off;
|
||||
proxy_buffering off;
|
||||
add_header X-Accel-Buffering no;
|
||||
# 超时设置(5分钟)
|
||||
fastcgi_read_timeout 300s;
|
||||
}
|
||||
|
||||
# 4. 静态资源缓存(assets/ 和 uploads/ 已在 public 目录下,无需 alias)
|
||||
# 静态资源缓存
|
||||
location /assets/ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# 5. 上传文件缓存
|
||||
# 上传文件缓存
|
||||
location /uploads/ {
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# 6. 禁止访问非公开目录(安全)
|
||||
location ~ /(app|config|vendor|tests|scripts|)/ {
|
||||
# 禁止访问非公开目录
|
||||
location ~ /(app|config|vendor|tests|scripts|\.cospec)/ {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
|
||||
# 7. 禁止访问隐藏文件
|
||||
# 禁止访问隐藏文件
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
return 404;
|
||||
}
|
||||
|
||||
# 8. 上传文件大小限制
|
||||
client_max_body_size 10m;
|
||||
|
||||
# ↑↑↑ 配置内容结束 ↑↑↑
|
||||
|
||||
Reference in New Issue
Block a user