ChatGPT 代理搭建
本文字数:805 字 | 阅读时长 ≈ 4 min

ChatGPT 代理搭建

本文字数:805 字 | 阅读时长 ≈ 4 min

1. 购买海外 VPS

1.1

1.2

1、更新环境

apt update -y && apt upgrade -y && apt install -y curl wget sudo socat
2、安装 Docker

curl -fsSL https://get.docker.com | sh
3、更新 apt-get 包索引:在终端中输入以下命令,以获取最新的包列表

sudo apt-get update
4、安装 socat:在终端中输入以下命令进行安装

sudo apt-get install socat
5、创建 Nginx 目录

mkdir -p /etc/nginx
touch /etc/nginx/nginx.conf
mkdir -p /etc/nginx/certs
6、域名申请证书(请将第三行与第四行代码中你的域名改为你解析好的域名)

curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com
~/.acme.sh/acme.sh --issue -d 你的域名 --standalone
~/.acme.sh/acme.sh --installcert -d 你的域名 --key-file /etc/nginx/certs/private.key --fullchain-file /etc/nginx/certs/cert.crt
7、安装 docker 环境

apt update && apt install docker.io -y

=================================

root@racknerd-64bab9:~# sudo apt update && apt install docker.io -y
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease                                                      
Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease                                                             
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~)
E: Unable to correct problems, you have held broken packages.

# 查看是否安装了 containerd
$ dpkg -l containerd*
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=(无)/须重装(R) (状态,错误:大写=故障)
||/ 名称                          版本                体系结构            描述
+++-=============================-===================-===================-===============================================================
ii  containerd                    1.5.5-0ubuntu3~18.0 amd64               daemon to control runC
rc  containerd.io                 1.6.6-1             amd64               An open and reliable container runtime

# 如果containerd不存在,则安装
sudo apt install containerd
# 如果containerd.io不存在,则安装
sudo apt-get install containerd.io

# 安装成功后再安装 docker.io
sudo apt-get install docker.io
# 查询版本
docker version

8、拉取镜像

docker pull pengzhile/pandora
9、启动docker容器web模式

docker run -e PANDORA_CLOUD=cloud -e PANDORA_SERVER=0.0.0.0:8899 -p 8899:8899 -d pengzhile/pandora
10、安装Nginx

apt install nginx
11、编辑Nginx配置文件,实现Nginx反向代理,分别修改两处域名位置与VPS公网IP和端口号

events {}

http {
server {

listen 80;

server_name 你的域名;

return 301 https://$host$request_uri;

}

server {

listen 443 ssl http2;

server_name 你的域名;

ssl_certificate /etc/nginx/certs/cert.crt;

ssl_certificate_key /etc/nginx/certs/private.key;

location / {

  proxy_pass http://你的VPS公网IP:8899;

  proxy_set_header Host $host;

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

}
12、重新加载 Nginx

nginx -s reload
13、每次 VPS 重启后在 finalshell(SSH)中执行此命令开启 web 模式,方可正常访问网站

docker run -e PANDORA_CLOUD=cloud -e PANDORA_SERVER=0.0.0.0:8899 -p 8899:8899 -d pengzhile/pandora
14、用账号登录 ChatGPT 官方网站后,浏览器新建标签页使用这个网址获取自己的 Token 即可登录自建的 ChatGPT 网站

https://chat.openai.com/api/auth/session
PS:详见视频教程