文章目录
一、起因和注意
1)起因
有墙
2)注意
①不建议为了调用openai把业务代码放国外,多少会有延迟
②因为业务在国内,所以大部分业务代码在国内的服务器,国内服务器调用代理服务器
二、实现方法(原理:透传)
1)nginx方案
配置nginx的服务器(改写nginx.conf )
server
{
listen 80;
server_name a.openaixx.com;
index index.html;
location / {
proxy_pass https://api.openai.com;
proxy_ssl_name api.openai.com;
proxy_ssl_server_name on;
proxy_set_header Host api.openai.com;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
chunked_transfer_encoding off;
proxy_read_timeout 3600;
proxy_buffering off;
proxy_cache off;
proxy_redirect off;
proxy_hide_header Cache-Control;
}
location ~ /.well-known {
allow all;
}
access_log off;
}
- 参考
传送门
2)node服务
3)纯 js 方案
复制以下代码,去 cloudflare 建立一个 worker 即可