背景
chatgpt屏蔽了很多地方的访问,使用起来很麻烦,现在的需求就是想使用本地网络就可以使用这个,那么可以通过nginx作代理进行访问
网络架构
本身的请求是直接发给openai的,这里我们使用一台服务器运行nginx,作为反向代理发送请求到api.openai.com
nginx配置文件
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 
 | server {listen       7480 default_server;
 server_name  _;
 root         /usr/share/nginx/html;
 
 
 include /etc/nginx/default.d/*.conf;
 
 location / {
 proxy_pass  https://api.openai.com/;
 proxy_set_header Host api.openai.com;
 proxy_set_header Connection '';
 proxy_http_version 1.1;
 chunked_transfer_encoding off;
 proxy_buffering off;
 proxy_cache off;
 proxy_set_header X-Forwarded-For $remote_addr;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_ssl_server_name on;
 proxy_ssl_session_reuse off;
 proxy_ssl_protocols TLSv1.2;
 }
 
 error_page 404 /404.html;
 location = /40x.html {
 }
 
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 }
 }
 
 | 
这个开的是80端口,可以自己设置
设置api_base
在python脚本里面设置下
openai.api_base=”http://myserver.com/v1“
设置好这个就可以使用了
请求是通过这个api地址转发的,如果有更多的地址进行设置即可
部署内网版本
搭建环境
| 1
 | bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
 | 
启动参数
| 1
 | OPENAI_API_KEY=sk-xxxx  CODE=passwd PROTOCOL=http BASE_URL=myid:7480  yarn start
 | 
然后就可以内网使用了