Maktub_Wiki Maktub_Wiki
主站 (opens new window)
  • 服务搭建
  • 网络服务
  • 开源框架
  • 操作系统
  • iOS/MacOS
  • 算法导论(Python)
  • Leetcode
  • 线性代数
主站 (opens new window)
  • 服务搭建
  • 网络服务
  • 开源框架
  • 操作系统
  • iOS/MacOS
  • 算法导论(Python)
  • Leetcode
  • 线性代数
  • Node.js

    • 脚本
  • Git

    • Github Actions
  • Caddy

    • 基础配置
    • abort应用
    • Caddy加速Docker
    • Caddy加速OpenAi api
    • V2ray

      • 入口分流
    • Realm

      • 多端口转发
    • Docker

      • 配置
    • NextCloud
    • Hexo
    • vuepress-theme-vdoing
    • 开源框架
    • Caddy
    Maktub_小明
    2025-02-09
    目录

    Caddy加速OpenAi api

    # Caddy配置文件

    example.com {
      handle /custom/path {
        rewrite /custom/path /v1/chat/completions
        @cors {
            method OPTIONS
        }
        header @cors {
            Access-Control-Allow-Origin: "*"
            Access-Control-Allow-Methods: "*"
            Access-Control-Allow-Headers: "*"
        }
        @post {
          method POST
        }
        reverse_proxy @post https://api.openai.com {
          header_up -*
          header_up User-Agent "curl/8.7.1"
          header_up Host {upstream_hostport}
          header_up Authorization {http.request.header.authorization}
          header_up Content-Type {http.request.header.content-type}
          header_down Access-Control-Allow-Origin "*"
        }
      }
      handle {
        abort
      }
    }
    

    # 说明

    • header_up -* 删除所有请求头
    • abort 拒绝所有其他请求

    # 参考

    • OPENAI API 代理折腾日记 (opens new window)
    上次更新: 2025/03/22, 03:52:10
    Caddy加速Docker
    入口分流

    ← Caddy加速Docker 入口分流→

    Theme by Vdoing | Copyright © 2021-2025 Maktub_小明 | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式