DEV Community

Justin Lee
Justin Lee

Posted on

用caddy代理币安的现货永续合约接口模板

用caddy代理币安的现货永续合约接口模板


# 假设域名为: proxy2.mydomain.xyz

https://proxy2.mydomain.xyz:443 {
    import block__cors

    # 代理 Binance 永续合约 (Futures)
    handle_path /bn/perp/* {
        reverse_proxy https://fapi.binance.com {
            header_up Host fapi.binance.com
            header_down -Proxy-Connection
            flush_interval 300ms
            transport http {
                dial_timeout 10s
                keepalive 10m
            }
        }
    }

    # 代理 Binance 现货 (Spot)
    handle_path /bn/spot/* {
        reverse_proxy https://api.binance.com {
            header_up Host api.binance.com
            header_down -Proxy-Connection
            flush_interval 300ms
            transport http {
                dial_timeout 10s
                keepalive 10m
            }
        }
    }


    # ----------------------------
    # 永续 WebSocket 代理
    # 访问示例: wss://d6.rrxia.xyz:443/ws/bn/perp/ws 会访问到 wss://fstream.binance.com/ws
    handle /ws/bn/perp/* {
    # 不做额外的 uri 改写,handle_path 会去掉 /ws/bn/perp 前缀
        reverse_proxy *  https://fstream.binance.com {
            header_up Host fstream.binance.com
            #header_up Connection {>Connection}
            #header_up Upgrade {>Upgrade}
            header_down -Proxy-Connection
            transport http {
                #versions 1.1
                dial_timeout 10s
                keepalive 10m
            }
        }
    }



    # 现货 WebSocket 代理
    # 访问示例: wss://d6.rrxia.xyz:443/ws/bn/perp/ws 会访问到 wss://stream.binance.com:9443/ws
    handle /ws/bn/spot/* {
        # 不做额外的 uri 改写,handle_path 会去掉 /ws/bn/spot 前缀
        reverse_proxy *  https://stream.binance.com:9443 {
            header_up Host fstream.binance.com
            #header_up Connection {>Connection}
            #header_up Upgrade {>Upgrade}
            header_down -Proxy-Connection
            transport http {
                #versions 1.1
                dial_timeout 10s
                keepalive 10m
            }
        }
    }


    # file proxy
    handle_path /openfile/* {
        root *  /home/datum/appdata/openfile
        file_server {
                hide *.git
                browse
        }
    }   
}


Enter fullscreen mode Exit fullscreen mode

Top comments (0)