Nginx宝塔反向代理OpenAI接口

2023年 6月 9日 84.2k 0

国外服务器,配置和带宽没要求,能跑nginx就行,线路不能太差不然体验不好(最好不是港澳台的,推荐美国)

Nginx配置

server {
        listen       80;
        server_name  localhost;
        root   html;
   location ^~ /
   {
    if ($request_method = 'OPTIONS') {
        return 204;
    }
    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Headers "Authorization,Cache-Control,Content-Type";

    proxy_pass https://api.openai.com;
    proxy_set_header Host api.openai.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Accept-Encoding "";
    proxy_ssl_session_reuse off;
    proxy_ssl_server_name on;
    proxy_buffering off;
    proxy_max_temp_file_size 0;
    resolver 8.8.8.8 ipv6=off;
    resolver_timeout 10s;
}

    }

宝塔控制面板配置如下

不建议开https,对速度有点影响。

# openai-API
location ^~ /
{
    if ($request_method = 'OPTIONS') {
        return 204;
    }
    add_header Access-Control-Allow-Origin "*";
    add_header Access-Control-Allow-Headers "Authorization,Cache-Control,Content-Type";

    proxy_pass https://api.openai.com;
    proxy_set_header Host api.openai.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Accept-Encoding "";
    proxy_ssl_session_reuse off;
    proxy_ssl_server_name on;
    proxy_buffering off;
    proxy_max_temp_file_size 0;
    resolver 8.8.8.8 ipv6=off;
    resolver_timeout 10s;
}

相关文章:

  1. [NGINX] – 配置文件优化 – NGINX.CONF
  2. nginx proxy_pass后的url加不加/的区别
  3. HTTP/3 原理实战
  4. Nginx Ngx_http_proxy_connect_module模块实现SSL正向代理

相关文章

LeaferJS 1.0 重磅发布:强悍的前端 Canvas 渲染引擎
10分钟搞定支持通配符的永久有效免费HTTPS证书
300 多个 Microsoft Excel 快捷方式
一步步配置基于kubeadmin的kubevip高可用
istio全链路传递cookie和header灰度
REST Web 服务版本控制

发布评论