标签搜索

目 录CONTENT

文章目录

websocket如何携带header或参数

高大北
2025-06-21 / 0 评论 / 1 点赞 / 29 阅读 / 235 字 / 正在检测是否收录...

这尼玛就是哥伪命题,谁家好人这么玩?如果前后端都是自己人,让他放弃吧,换成别的方式比如query_parm形式。

如果是三方应用没办法怎么办?草!比如我这次对接的阿里云的ws服务,尼玛让我ws放token.我是Vue啊大哥,我怎么玩?

算了哥们直接给出方案吧。

通过nginx代理一层解决。

下面给出nginx的配置方案

WebSocket代理配置

location /api-ws/v1/inference {
    proxy_pass https://dashscope.aliyuncs.com/api-ws/v1/inference;   # ws的真实地址
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host dashscope.aliyuncs.com;   # 目标地址的主机头
    proxy_set_header Authorization "自定义key1";
    proxy_set_header X-DashScope-DataInspection "自定义key2";
    # 超时和SSL配置
    proxy_read_timeout 1000s;
    proxy_ssl_server_name on;  # 启用SNI
    proxy_ssl_protocols TLSv1.2;
}
1
博主关闭了所有页面的评论