-
Notifications
You must be signed in to change notification settings - Fork 11.8k
docs: 添加中文部署教程(完整版+快速上手版) #7568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # New API 10分钟快速部署教程 | ||
|
|
||
| > 从零开始,10分钟搭建属于你自己的 AI API 中转站。本教程追求最快上手,不啰嗦。 | ||
|
|
||
| ## 准备工作 | ||
|
|
||
| - 一台云服务器(Ubuntu 22.04,1核2G够用) | ||
| - 一个域名(已解析到服务器IP) | ||
| - 一个大模型 API Key(DeepSeek/智谱/讯飞都行,用来测试) | ||
|
|
||
| --- | ||
|
|
||
| ## 第一步:安装 Docker(2分钟) | ||
|
|
||
| SSH 登录服务器,执行: | ||
|
|
||
| ```bash | ||
| curl -fsSL https://get.docker.com | bash | ||
| systemctl enable docker --now | ||
| ``` | ||
|
|
||
| 验证:`docker --version`,看到版本号就成功了。 | ||
|
|
||
| --- | ||
|
|
||
| ## 第二步:启动 New API(2分钟) | ||
|
|
||
| ```bash | ||
| mkdir -p /opt/new-api/data | ||
|
|
||
| docker run -d \ | ||
| --name new-api \ | ||
| --restart always \ | ||
| -p 127.0.0.1:3000:3000 \ | ||
| -v /opt/new-api/data:/data \ | ||
| calciumion/new-api:latest | ||
| ``` | ||
|
|
||
| 验证:`docker ps | grep new-api`,看到 Up 状态就成功了。 | ||
|
|
||
| --- | ||
|
|
||
| ## 第三步:配置 Nginx 反代(2分钟) | ||
|
|
||
| ```bash | ||
| apt install nginx -y | ||
| ``` | ||
|
|
||
| 创建配置文件 `/etc/nginx/sites-available/new-api`: | ||
|
|
||
| ```nginx | ||
| server { | ||
| listen 80; | ||
| server_name 你的域名; | ||
|
|
||
| client_max_body_size 64M; | ||
|
|
||
| location / { | ||
| proxy_pass http://127.0.0.1:3000; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Upgrade $http_upgrade; | ||
| proxy_set_header Connection "upgrade"; | ||
| proxy_read_timeout 300s; | ||
| proxy_buffering off; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 启用配置: | ||
|
|
||
| ```bash | ||
| ln -s /etc/nginx/sites-available/new-api /etc/nginx/sites-enabled/ | ||
| nginx -t && systemctl reload nginx | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 第四步:配置 HTTPS(1分钟) | ||
|
|
||
| ```bash | ||
| apt install certbot python3-certbot-nginx -y | ||
| certbot --nginx -d 你的域名 | ||
| ``` | ||
|
|
||
| 按提示输入邮箱,选 2(强制跳转 HTTPS)。 | ||
|
|
||
| --- | ||
|
|
||
| ## 第五步:初始配置(2分钟) | ||
|
|
||
| 1. 浏览器访问 `https://你的域名` | ||
| 2. 用默认账号登录:用户名 `root`,密码 `123456` | ||
| 3. **立即修改密码**:右上角头像 → 个人设置 → 修改密码 | ||
| 4. 进入管理后台 → 系统设置,修改站点名称,开启注册 | ||
|
|
||
| --- | ||
|
|
||
| ## 第六步:添加模型渠道(1分钟) | ||
|
|
||
| 1. 管理后台 → 渠道 → 添加渠道 | ||
| 2. 以 DeepSeek 为例: | ||
| - 渠道类型:DeepSeek | ||
| - 名称:随便起 | ||
| - 密钥:你的 DeepSeek API Key | ||
| - 模型:deepseek-chat, deepseek-reasoner | ||
| 3. 点「测试」,成功后点「提交」 | ||
|
|
||
| --- | ||
|
|
||
| ## 第七步:配置模型价格(必做!) | ||
|
|
||
| ⚠️ **不配置价格,模型不会显示,也无法调用!** | ||
|
|
||
| 1. 管理后台 → 模型 → 模型定价 | ||
| 2. 给每个模型设置输入/输出价格(参考官方价格适当加价) | ||
| 3. 保存 | ||
|
|
||
| --- | ||
|
|
||
| ## 第八步:测试调用 | ||
|
|
||
| 1. 管理后台 → 令牌 → 添加令牌,创建一个 API Key | ||
| 2. 用 curl 测试: | ||
|
|
||
| ```bash | ||
| curl https://你的域名/v1/chat/completions \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "Authorization: Bearer 你的APIKey" \ | ||
| -d '{"model":"deepseek-chat","messages":[{"role":"user","content":"你好"}],"stream":false}' | ||
| ``` | ||
|
|
||
| 看到返回内容,恭喜你,部署成功!🎉 | ||
|
|
||
| --- | ||
|
|
||
| ## 常见坑(提前避开) | ||
|
|
||
| | 问题 | 原因 | 解决 | | ||
| |------|------|------| | ||
| | 502 Bad Gateway | 容器没启动或Nginx配置错 | `docker ps` 检查容器,`nginx -t` 检查配置 | | ||
| | 模型列表为空 | 没配置模型价格 | 去模型定价里给所有模型设价格 | | ||
| | 调用404 | 模型名写错或渠道没加这个模型 | 检查渠道的模型列表和调用时的模型名 | | ||
| | 权限不足 | 用户角色异常 | 管理后台→用户,把角色改成普通用户 | | ||
| | SSH连不上 | 触发fail2ban | 等10分钟自动解封,或用VNC登录 | | ||
| | 流式输出卡顿 | Nginx缓冲没关 | 确认配置里有 `proxy_buffering off` | | ||
|
|
||
| --- | ||
|
|
||
| ## 下一步 | ||
|
|
||
| - 配置支付(彩虹易支付)→ 参考完整教程 | ||
| - 配置兑换码 → 管理后台确认合规条款后启用 | ||
| - 开启注册赠送额度 → 系统设置里设置 RegisterQuota | ||
| - 配置定时备份 → 每天自动备份数据库 | ||
|
|
||
| --- | ||
|
|
||
| **项目地址:** https://github.com/QuantumNous/new-api | ||
| **官方文档:** https://docs.newapi.ai | ||
|
|
||
| > 遇到问题先看容器日志:`docker logs -f new-api` |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||
| **解决:** 登录易支付商户后台,在域名管理中添加你的域名,等待审核通过。 | ||||||
|
|
||||||
|
|
||||||
| ### Q5:SSH 连接超时/被拒绝 | ||||||
|
|
||||||
|
|
||||||
| **原因:** 可能触发了服务器的 fail2ban 防护,或 SSH 服务异常。 | ||||||
|
|
||||||
|
|
||||||
| **解决:** | ||||||
| - 等待一段时间(通常 10-30 分钟自动解封) | ||||||
| - 通过云服务商的 VNC/控制台登录服务器 | ||||||
| - 检查 fail2ban 状态:`fail2ban-client status sshd` | ||||||
| - 解封 IP:`fail2ban-client set sshd unbanip 你的IP` | ||||||
|
|
||||||
|
|
||||||
| ### Q6:流式输出卡顿或中断 | ||||||
|
|
||||||
|
|
||||||
| **原因:** Nginx 缓冲或超时设置问题。 | ||||||
|
|
||||||
|
|
||||||
| **解决:** 在 Nginx 配置中添加: | ||||||
| ```nginx | ||||||
| proxy_buffering off; | ||||||
| proxy_cache off; | ||||||
| proxy_read_timeout 300s; | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| ### Q7:数据库锁定(SQLite busy) | ||||||
|
|
||||||
|
|
||||||
| **原因:** SQLite 并发写入限制,用户量较大时容易出现。 | ||||||
|
|
||||||
|
|
||||||
| **解决:** 切换到 MySQL 数据库,在 docker-compose.yml 中添加 SQL_DSN 环境变量。 | ||||||
|
|
||||||
|
|
||||||
| ### Q8:忘记管理员密码 | ||||||
|
|
||||||
| New API 镜像未提供密码重置命令行参数,需直接修改 SQLite 数据库中的密码哈希。 | ||||||
|
|
||||||
| **解决:** | ||||||
| ```bash | ||||||
| # 进入容器 | ||||||
| docker exec -it new-api bash | ||||||
|
|
||||||
| # 用 sqlite3 将 root 密码重置为 123456 | ||||||
| # 下面的哈希值是 "123456" 的 bcrypt 哈希(cost=10) | ||||||
| sqlite3 /data/one-api.db "UPDATE users SET password='$2b$10$AQK.o3B9HyAKbNCEbPSYO.AVum1WW8dbGyzbKSPEXWJMUpx8nE4Oi' WHERE username='root';" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Preserve the bcrypt hash through Bash. If Proposed fix-sqlite3 /data/one-api.db "UPDATE users SET password='$2b$10$AQK.o3B9HyAKbNCEbPSYO.AVum1WW8dbGyzbKSPEXWJMUpx8nE4Oi' WHERE username='root';"
+sqlite3 /data/one-api.db "UPDATE users SET password='\$2b\$10\$AQK.o3B9HyAKbNCEbPSYO.AVum1WW8dbGyzbKSPEXWJMUpx8nE4Oi' WHERE username='root';"📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: MCP tools 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Make the SQLite CLI available in the documented container. The command runs inside 🤖 Prompt for AI AgentsSource: MCP tools |
||||||
|
|
||||||
| # 验证是否更新成功(应返回 1) | ||||||
| sqlite3 /data/one-api.db "SELECT changes();" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Run the change check on the same SQLite connection. This line starts a new 🤖 Prompt for AI AgentsSource: MCP tools |
||||||
|
|
||||||
| # 退出容器 | ||||||
| exit | ||||||
|
|
||||||
| # 重启容器使密码生效 | ||||||
| docker restart new-api | ||||||
| ``` | ||||||
|
|
||||||
| > **提示:** 重置后请使用 `root / 123456` 登录,并立即在「个人设置」中修改为强密码。 | ||||||
| > | ||||||
| > 如需设置其他密码,可在本地用 Python 生成 bcrypt 哈希: | ||||||
| > ```bash | ||||||
| > python3 -c "import bcrypt; print(bcrypt.hashpw(b'你的密码', bcrypt.gensalt(rounds=10)).decode())" | ||||||
| > ``` | ||||||
|
|
||||||
|
|
||||||
| --- | ||||||
|
|
||||||
|
|
||||||
| ## 进阶配置 | ||||||
|
|
||||||
|
|
||||||
| ### 使用 MySQL 数据库 | ||||||
|
|
||||||
|
|
||||||
| 当用户量较大时,建议使用 MySQL 替代 SQLite: | ||||||
|
|
||||||
|
|
||||||
| 1. 安装 MySQL 并创建数据库 | ||||||
| 2. 在 docker-compose.yml 中添加环境变量: | ||||||
| ```yaml | ||||||
| environment: | ||||||
| - SQL_DSN=用户名:密码@tcp(127.0.0.1:3306)/数据库名?charset=utf8mb4&parseTime=True&loc=Local | ||||||
| ``` | ||||||
| 3. 重启容器 | ||||||
|
|
||||||
|
|
||||||
| ### 配置内容审核 | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 3797
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 20606
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 4216
补全完整教程中的支付配置章节。
快速教程第 154 行要求用户参考完整教程配置彩虹易支付,但完整教程从 Q5 开始,只有一条残缺的支付故障解决语句,没有支付配置步骤。用户完成快速部署后无法按该引用完成支付配置。
请在 Q5 前恢复支付配置章节,或将该引用改为实际包含这些步骤的文档。当前证据不支持“相对 PR base 删除了既有教程”的说法,因为两个教程文件在该 base 中都不存在。
🤖 Prompt for AI Agents