chatgpt的反向代理设置

发布于:2023-07-04 ⋅ 阅读:(116) ⋅ 点赞:(0)

背景

chatgpt屏蔽了很多地方的访问,使用起来很麻烦,现在的需求就是想使用本地网络就可以使用这个,那么可以通过nginx作代理进行访问

网络架构

本身的请求是直接发给openai的,这里我们使用一台服务器运行nginx,作为反向代理发送请求到api.openai.com

nginx配置文件

    server {
        listen       7480 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        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地址转发的,如果有更多的地址进行设置即可

部署内网版本

搭建环境

bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)

启动参数

OPENAI_API_KEY=sk-xxxx  CODE=passwd PROTOCOL=http BASE_URL=myid:7480  yarn start

然后就可以内网使用了

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到