【问题标题】:WebSocket proxying with nginx使用 nginx 进行 WebSocket 代理
【发布时间】:2017-12-01 17:30:26
【问题描述】:

我对 Web 套接字代理的 nginx 文档感到困惑。

来自此处的文档:https://nginx.org/en/docs/http/websocket.html

一个更复杂的示例,其中“连接”的值 对代理服务器的请求中的标头字段取决于 客户端请求标头中存在“升级”字段:

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    server {
        ...

        location /chat/ {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }

我想要类似的东西,如果升级标头已预设,我想在连接中传递升级,否则我想做相当于proxy_set_header Connection ""

如果没有 Upgrade 标头,我认为文档中的示例正在执行proxy_set_header Connection close?如果是这样,我该如何修改map 来做我想做的事。看来我需要做proxy_set_header Connection "" as

map $http_upgrade $connection_upgrade {
   default upgrade;
   ''      '';
}

但感觉有些不对劲。

【问题讨论】:

    标签: nginx nginx-reverse-proxy


    【解决方案1】:

    配置

    map $http_upgrade $connection_upgrade {
       default upgrade;
       ''      '';
    }
    

    确实做了我想做的事。

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多