Files
chat-app/DEPLOY.md
T
wangyang 6b26ccb1e4 fix: 登录后自动加载对话历史;新增生产部署指南 DEPLOY.md
- 修复 useChat useEffect 只在挂载时执行导致的登录后无历史问题
- 暴露 reloadConversations 函数,App.tsx 登录成功后主动调用
- 添加 DEPLOY.md 生产部署文档(Nginx + PHP-FPM)

2026-05-15
2026-05-15 18:20:39 +08:00

95 lines
1.9 KiB
Markdown

# 生产部署指南
## 目录结构
```
/www/chat-app/
├── public/ # 前端 dist + PHP 入口
│ ├── index.html # 前端入口
│ ├── assets/ # 前端 JS/CSS
│ └── index.php # PHP 后端入口
├── src/ # PHP 业务代码
├── vendor/ # composer 依赖
├── chat.db # SQLite 数据库
└── composer.json
```
## 部署步骤
### 1. 安装 PHP 依赖
```bash
cd /www/chat-app
composer install --no-dev --optimize-autoloader
```
### 2. 前端构建并放入 public
本地执行:
```bash
npm run build
cp -r dist/* server/public/
```
### 3. Nginx 配置
```nginx
server {
listen 80;
server_name your-domain.com;
root /www/chat-app/public;
index index.html index.php;
# 前端静态资源(JS/CSS/图片等)
location /assets/ {
try_files $uri =404;
expires 1y;
add_header Cache-Control "public, immutable";
}
# API 请求 → PHP
location /api/ {
try_files $uri /index.php$is_args$args;
}
# 前端路由(SPA)→ index.html
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; # 或 unix:/run/php/php8.3-fpm.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
### 4. PHP-FPM 配置要点
确保 `php.ini` 中:
```ini
; SQLite 需要
extension=pdo_sqlite
; SSE 流式输出需要
output_buffering = Off
zlib.output_compression = Off
```
### 5. 数据库权限
```bash
chmod 666 /www/chat-app/chat.db
```
## 简化版:PHP 内置服务器(仅测试)
```bash
cd /www/chat-app/public
php -S 0.0.0.0:8000
```
> 注意:PHP 内置服务器性能差,不适合生产。