fix: 维护一下远古文章们
This commit is contained in:
@@ -10,17 +10,18 @@ banner_img: /img/2024/1/25/openai.jpg
|
||||
permalink: /articles/2024/openai-proxy.html
|
||||
date: 2024-01-25 09:27:45
|
||||
---
|
||||
在去年(2023年),我看到了极客湾的这个视频:[我们做了个能对话的AI派蒙,免费给大家玩!](https://b23.tv/Ap27xLS)
|
||||
觉得很有意思,但是由于没有显卡且不敢翻墙,一直没有机会尝试,但最近搞来了一块RTX A2000(目前这卡性价比很低,不推荐),便想着折腾一下
|
||||
由于不敢翻墙,只能使用反向代理的方式来访问openai api
|
||||
|
||||
## 准备
|
||||
|
||||
你需要:
|
||||
|
||||
* 一个Cloudflare账户
|
||||
* Cloudflare账户中有未被墙的有效域名(若有下一项,则为可选项)
|
||||
* 一台高速的非中国大陆服务器(配置不用太高,可选)(若无此项,则上一项为必选)
|
||||
* 一个好用的脑子
|
||||
|
||||
## Cloudflare worker
|
||||
|
||||
创建一个Cloudflare worker,并把一下代码塞入其中(代码来自[这里](https://gitee.com/GoGPTAI/ChatGPT-Proxy))
|
||||
|
||||
```
|
||||
@@ -50,14 +51,17 @@ async function handleRequest(request) {
|
||||
return modifiedResponse;
|
||||
}
|
||||
```
|
||||
|
||||
使用Cloudflare理论上可以降低被封的概率
|
||||
由于workers.dev被墙了,所以需要在“触发器”中换用你的域名(如果有非中国大陆服务器则可以跳过这一步)
|
||||
如果你没有非中国大陆服务器,那么这篇文章就结束了
|
||||
|
||||
## 反向代理加速
|
||||
|
||||
众所周知,cloudflare在中国大陆的访问速度极慢,所以可以使用自己的服务器套一层加速
|
||||
我这里使用一台香港CN2GIA线路的服务器和nginx做演示
|
||||
(或许你可以去导航栏的推广页看看,那里获取会有这种服务器,如果那个页面在你看到的时候还在)
|
||||
|
||||
```nginx
|
||||
location ^~ / {
|
||||
proxy_pass https://xxx.xxx.workers.dev;
|
||||
@@ -74,8 +78,10 @@ location ^~ / {
|
||||
add_header Cache-Control no-cache;
|
||||
}
|
||||
```
|
||||
|
||||
使用面板创建的反向代理是这样的,但是你会发现这是访问显示502
|
||||
这是因为Nginx在建立SSL/TLS连接时没有发送服务名到后端服务器,导致导致后端服务器使用错误的证书或拒绝连接,所以需要做以下修改:
|
||||
|
||||
```nginx
|
||||
location ^~ / {
|
||||
proxy_pass https://xxx.xxx.workers.dev;
|
||||
@@ -101,8 +107,10 @@ location ^~ / {
|
||||
proxy_ssl_server_name on; # 使Nginx在建立SSL/TLS连接时发送服务名到后端服务器
|
||||
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 指定Nginx应该使用的SSL/TLS协议版本
|
||||
```
|
||||
|
||||
访问`://YOURHOSTNAME/v1/chat/completions`
|
||||
若出现以下回复就配置成功了
|
||||
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
@@ -115,5 +123,6 @@ proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 指定Nginx应该使用的SSL/TLS
|
||||
```
|
||||
|
||||
### 参考文章
|
||||
|
||||
[最新宝塔反代openai官方API开发接口详细搭建教程,解决502 Bad Gateway问题](https://blog.csdn.net/weixin_43227851/article/details/134404942)
|
||||
[ChatGPT-Proxy](https://gitee.com/GoGPTAI/ChatGPT-Proxy)
|
||||
[ChatGPT-Proxy](https://gitee.com/GoGPTAI/ChatGPT-Proxy)
|
||||
|
||||
Reference in New Issue
Block a user