018 ChatGPT-Next-Web 部署
2025/6/10约 1379 字大约 5 分钟
资源地址
ChatGPT-Next-Web 官网: https://nextchat.club/
ChatGPT-Next-Web GitHub 项目: https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web
Nginx 官网文档: http://nginx.org/en/docs/
安装docker
注意
官网要求 docker 版本必须 >= 20.00
dnf install docker下载镜像/启动容器
# 1. 拉取官方项目镜像
docker pull yidadaa/chatgpt-next-web
# 2. 在宿主机上保存该镜像,给别的机器使用
docker save -o chatgpt-2.10.1.tar yidadaa/chatgpt-next-web:latest
# 3. 加载使用save参数保存的镜像文件
docker load -i chatgpt-2.10.1.tar
# 4. 使用docker import *.tar,可能是因为该镜像不是通过save参数保存的,而是系统的快照。
# save可完整记录docker镜像内容,而系统快照不可以
# 5. 加载镜像后,查看当前系统镜像列表
docker images
# 6. 首次启动容器
docker start <容器ID或容器名>
# 7. 进入已启动的容器
docker exec -it <容器ID或容器名> /bin/bash
# 8. 查看刚才启动的容器列表
docker ps使用 nginx 设置 HTTP 重定向 HTTPS,并开启证书
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
# root /usr/share/nginx/html;
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
return 301 https://$host$request_uri;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name _;
# root /usr/share/nginx/html;
ssl_certificate "/etc/pki/nginx/server.crt";
ssl_certificate_key "/etc/pki/nginx/private/server.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:3000; # 转发规则
proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
# error_page 404 /404.html;
# location = /404.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
}
}部署服务+ 配置 HTTPS 全流程
提示
已部署验证环境:
- Fedora 39 Linux 发行版环境(阿里云 ECS 服务器)
- Docker 版本 >= 20
1. 部署服务
进入云服务器,安装 docker,以及按需安装其它工具
# 安装 docker 容器 sudo dnf install docker # 启动并自启动 docker 服务 sudo systemctl start docker sudo systemctl enable docker拉取 ChatGPT-Web-Next 最新镜像
sudo docker pull yidadaa/chatgpt-next-web启动容器(可将下面命令保存为脚本)
# 启动并后台运行 ChatGPT-Web-Next 服务容器 # # 1. -d 后台运行容器 # 2. -p 3000:3000 指定 宿主机:容器 端口映射 # 3. -e OPENAI_API_KEY=sk-xxx 配置GPT API密钥 # 4. -e CODE=your-password 设置访问密码(建议32位) # 5. -e PROXY_URL=URL API代理网址(使用官网API可不设置,但官网需要魔法。使用代理网址,可绕过限制,同时第3点需配置代理网址给的 密钥) # 6. -e HIDE_USER_API_KEY=1 禁止其它用户输入自己的 API 密钥(允许则删除该变量) # 7. -e DISABLE_GPT4=1 禁止使用 GPT-4(允许则删除该变量) # 8. -e ENABLE_BALANCE_QUERY=1 允许用户查询余额(禁止则删除该变量) # 9. yidadaa/chatgpt-next-web 镜像名称 docker run -d -p 3000:3000 \ -e OPENAI_API_KEY=sk-xxxx \ -e CODE=your-password \ -e PROXY_URL=http://localhost:7890 \ yidadaa/chatgpt-next-web到此,应该可以通过
http://IP:3000或http://域名:3000访问容器的web服务。
2. 配置 HTTPS 访问
获取 CA 证书,如通过阿里云控制台获取有效期1年的免费域名证书。包含公钥和私钥。
安装 nginx 反向代理、防火墙配置软件
# 安装 nginx sudo dnf install nginx # 安装 firewalld 防火墙 sudo dnf install firewalld配置 HTTPS 服务模块
# 进入 nginx 配置文件 vim /etc/nginx/nginx.conf # 启用 HTTPS 服务。将对应行取消注释,并更新实际值 # TODO: 待补充使用 firewalld 配置防火墙
# 启动 防火墙 服务 sudo systemctl start firewalld sudo systemctl enable firewalld # 设置永久允许 443 端口流量通行 sudo firewall-cmd --permanent --add-port=443/tcp # 重新加载使防火墙配置生效 sudo firewall-cmd --reload至此,应该可以通过
https://IP或https://域名访问服务了。
自定义阿里百炼大模型平台 deepseek-r1 模型
- ChatNext Web 页面的设置中,开启
自定义接口(是否使用自定义Azure或OpenAI服务) - 出现模型服务商,选择
Alibaba - 接口地址不填,或者保持默认。
- 填写接口秘钥,即百炼大模型平台自创建的 API-key
- 自定义模型名填写
deepseek-r1@Alibaba - 新建聊天,即可发现当前聊天模型在最上面,名称是
deepseek-r1(Alibaba)
通过 ChatGPTNext 源码构建容器镜像
- 配置 openEuler 局域网 repo 源,下载 docker 软件包。
- 为docker repo配置加速器:
# /etc/docker/daemon.json { "registry-mirrors": [ "https://docker.1ms.run", "https://docker.xuanyuan.me" ] } - 若此时拉取镜像依然网络失败,可以配置外网代理,取消TLS/SSL证书校验:
# /etc/systemd/system/docker.service.d/proxy.conf [Service] Environment="HTTP_PROXY=xxx" Environment="HTTPS_PROXY=xxx" Environment="NO_PROXY=localhost,127.0.0.1,.internal" Environment="DOCKER_OPTS=--insecure-registry" - 重启服务
systemctl daemon-reload systemctl restart docker - 进入项目根目录,开始通过 Dockerfile 文件构建镜像:
docker build -t my-chatgpt-web:latest . - 导出镜像压缩文件
docker save -o my-chatgpt-web.tar my-chatgpt-web:latest
FAQ
使用 -p 端口映射,导致后面端口冲突
# 清除所有链接,包括端口映射
iptables -t filter -F
iptables -t filter -X
# 重启 docker 服务
systemctl restart docker