前提:谷歌云服务器,chatgpt的key。(这些网上有教程,自行注册获取。)
1.更新yum
yum update
2.下载docker-ce的repo
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
3.安装依赖(这是相比centos7的关键步骤)此过程可能需要一路输入 y
yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
4.安装docker-ce
yum install docker-ce
5.启动docker
systemctl start docker
6.开机启动docker
systemctl enable docker
7.安装wget命令
yum -y install wget
8.安装docker-compose
sudo wget https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m) -O /usr/local/bin/docker-compose
9.添加操作权限
sudo chmod +x /usr/local/bin/docker-compose
10.设置快捷
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
11.查看docker-compose 版本
docker-compose --version
12.创建docker-compose.yml文件
(1)在服务器上创建一个目录:chatgpt_web
mkdir chatgpt_web && cd chatgpt_web
(2)创建docker-compose.yml文件
vim docker-compose.yml
(3)以下内容填写到yml配置文件中并保存
version: '3'
services:
app:
image: chenzhaoyu94/chatgpt-web:latest
ports:
- 3002:3002
environment:
OPENAI_API_KEY: skxxxxxxxxxxxxxxxx #修改为自己申请的秘钥
TIMEOUT_MS: 60000
保存: 按下Esc,然后输入 :wq 回车
注意:大家在编写yml文件时。要把注释删掉,否则有可能会报错。
13.部署并启动运行
docker-compose up -d
14.登录chatgpt_web页面
http://服务器ip:3002
运行成功后直接访问(服务器需要开放3002端口)。
前提:服务器安装node(版本最好是16,18,19),还有pnpm,git,操作如下。
安装 node:
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs
安装pnpm:
npm install -g n
安装git:
yum install git
1.找个文件夹,执行以下,克隆以下项目。
git clone https://github.com/Chanzhaoyu/chatgpt-web.git
2.根目录下运行以下命令。
pnpm bootstrap
3.执行。
pnpm build
4.执行完会生成dist的文件夹,nginx配置的时候需要用到。
1.安装nginx
yum install nginx
2.在/etc/nginx目录下,新建ssl文件夹,把https的证书放进去。
mkdir ssl
3.在/etc/nginx/conf.d目录下,生成.conf的文件。名字随意,例如:xxx.conf。
cd /etc/nginx/conf.d
touch xxx.conf
4.编辑xxx.conf的文件
vim xxx.conf
5.把以下内容复制粘贴进去
server {
listen 80;
server_name www.xxx.com;#你的域名
server_tokens off;
access_log / dev / null;
if ($request_method!~ ^ (GET | HEAD | POST | OPTIONS) $) {
return 444;
}
location / {
rewrite ^ /(.*)$ https:/ / server_name / $1 permanent;
}
}
server {
listen 443 ssl http2;
server_name www.xxx.com;#你的域名
server_tokens off;
ssl_certificate ssl / xxx.pem;#你的证书的名称
ssl_certificate_key ssl / xxx.key;#你的证书的名称
ssl_protocols TLSv1 TLSv1 .1 TLSv1 .2 TLSv1 .3;
ssl_ciphers TLS13 - AES - 256 - GCM - SHA384: TLS13 - CHACHA20 - POLY1305 - SHA256: TLS13 - AES - 128 - GCM - SHA256: TLS13 - AES - 128 - CCM - 8 - SHA256: TLS13 - AES - 128 - CCM - SHA256: EECDH + CHACHA20: EECDH + CHACHA20 - draft: EECDH + ECDSA + AES128: EECDH + aRSA + AES128: RSA + AES128: EECDH + ECDSA + AES256: EECDH + aRSA + AES256: RSA + AES256: EECDH + ECDSA + 3 DES: EECDH + aRSA + 3 DES: RSA + 3 DES: !MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared: SSL: 50 m;
ssl_session_timeout 1 d;
ssl_session_tickets on;
ssl_stapling on;
ssl_stapling_verify on;
resolver 114.114 .114 .114 valid = 300 s;
resolver_timeout 10 s;
access_log /
var / log / xxx.log;
if ($request_method!~ ^ (GET | HEAD | POST | OPTIONS) $) {
return 444;
}
add_header Access - Control - Allow - Origin * ;
add_header Strict - Transport - Security "max-age=63072000; includeSubdomains; preload";
add_header X - Frame - Options ALLOW - FROM;
add_header X - Frame - Options SAMEORIGIN;
add_header X - Content - Type - Options nosniff;
add_header X - XSS - Protection "1; mode=block";
root / home / chatgpt - code / chatgpt - web / dist;#前端dist的目录
index index.html index.htm index.php;
location~.*\.(gif | jpg | jpeg | png | js | css) $ {
expires max;
}
location~/(images|static|uploads|downloads)/.*\.(php | php5) ? $ {
deny all;
}
location / api / {
proxy_pass http: //localhost:3002;
proxy_buffering off;
chunked_transfer_encoding on;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X - Real - IP $remote_addr;
proxy_set_header X - Forwarded - For $proxy_add_x_forwarded_for;
}
location~/\. {
deny all;
}
}
6.nginx -t看配置文件是否正常。
7.nginx -c /etc/nginx/nginx.conf,启动nginx
到这里就成功了,网页打开Https://你的域名。