部署AI对话技术
具体网址
使用入口:
部署参考
- 阿里云服务器部署网页参考:
- chatgpt开源项目参考:
- ubuntu设置代理参考:
- 反向代理参考:
自己部署过程中几个修改的地方
部署过程中,想要让程序运行在7860端口,并且跳转过后不显示7860端口,显示运行在子域名 ailab.com/ailab-chat 设置如下:
- 运行主程序中修改
在ChuanhuChatbot.py中修改,让程序能通过域名后边的 “/ailab-chat” 的子目录访问:
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
blocked_paths=["config.json"],
server_name=server_name,
server_port=server_port,
share=share,
auth=auth_from_conf if authflag else None,
favicon_path="./web_assets/favicon.ico",
inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
root_path="/ailab-chat", # 添加了这里
)
- 修改程序在云服务器本地的运行端口
/home/tp/project/003-gpt/config.json 文件中自定义程序运行的 IP(用127.0.01本地跳转)和端口7860:
- 修改前端页面中的跳转
前端页面文件 index_gpt.html 中 <点此进入 点击后即可对应的跳转到子域名位置来转到该程序执行界面:
修改后界面如下:
4. 服务器的nginx文件中配置反向代理
计划修改反向代理,要修改nginx的配置文件,先看一下服务器中的配置文件 /etc/nginx/conf.d/index.conf 原始内容如下:
server {
listen 80;
server_name ***.***.***.*** ailab.com www.ailab.com; # 星号为IP地址,修改成自己的IP地址
location / {
root /home/tp/project/003-gpt/website; # 修改成自己的文件目录
index index.html index.htm; # 文件目录下的前端界面文件
try_files $uri $uri/ /index.html;
}
}
添加域名下子目录的反向代理(隐藏开放的端口不直接暴露,一定程度上保证安全),修改后如下:
server {
listen 80;
server_name ***.***.***.*** ailab.com www.ailab.com; # 星号为IP地址,修改成自己的IP地址
location / {
root /home/tp/project/003-gpt/website; # 修改成自己的文件目录
index index.html index.htm; # 文件目录下的前端界面文件
try_files $uri $uri/ /index.html;
}
# 设置反向代理,/ailab-chat/为域名后的子域名,7860为代理指向的端口,可以设置不同的子域名跳转。
location /ailab-chat/ {
proxy_pass http://127.0.0.1:7860/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
location /ailab-chat-4.0/ {
proxy_pass http://127.0.0.1:7861/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
- 阿里云服务器开放此端口允许外部访问
阿里云服务器上打开端口: - 最终实现效果如下图,该程序运行在了云服务器的7860端口,但是不显示 “7860”,而是代替显示了 /ailab-chat 这个子域名: