这篇文章上次修改于 680 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

最近使用搭建的用来访问chatgpt的vps的ip被封了,打开就是1002,更换ip不但不一定有用,还很贵,因此更好的解决办法是使用cloudflare提供的warp工具,解锁openai访问,一劳永逸(失败,cloudflareip也被限制了)

下面内容转载自https://silentming.net/blog/2023/03/27/using-cfwraper/

CloudFlare Warp

官方安装指导: https://pkg.cloudflareclient.com/install

按照官方教程添加对应的源,并安装: (以ubuntu为例)

 # Install
 apt install cloudflare-warp

 # Register device
 warp-cli register

 # 打开代理模式
 warp-cli set-mode proxy

 # 连接Warp
 warp-cli connect

验证效果:

# Check current IP (return proxy ip)
curl ifconfig.me --proxy socks5://127.0.0.1:40000

上面会显示现在经过warp后的IP

# Check ChatGPT
curl chat.openai.com
curl chat.openai.com --proxy socks5://127.0.0.1:40000

如果配置正确的话,前者会返回1020的错误,后者则没有返回

配置V2Ray

如果有桌面,那么直接设置socks5的代理就可以了,对于使用V2ray (xray)的用户,可以设置一层转发:

在outbounds里添加新的outbounds:

/usr/local/etc/v2ray/config.json
"outbounds": [
    { ... }, // Original outbounds
     {
         "tag": "chatgpt_proxy",
         "protocol": "socks",
         "settings": {
             "servers": [
                 {
                     "address": "127.0.0.1",
                     "port": 40000
                 }
             ]
         }
     }
]

在routing里面添加路由规则:

/usr/local/etc/v2ray/config.json
"routing": {
    "rules": [
        { ... }, // Original rules
        {
            "type": "field",
            "outboundTag": "chatgpt_proxy",
            "domain": [
                "openai.com"
            ],
            "enabled": true
        }
    ]
}