V2ray-core: [discussion] caddy 的 websocket 配置下 header_upstream 的作用是什么?

Created on 20 Sep 2018  ·  4Comments  ·  Source: v2ray/v2ray-core

在 caddy + tls + websocket 的配置下,网上大部分教程都建议如下的配置:

  proxy /ray localhost:10000 {
    websocket
    header_upstream -Origin
  }

不太明白 header_upstream -Origin 的作用是什么,经过测试,该行是否存在都不影响 websocket 的正常工作。

类似的,以下两种配置,也不影响 websocket 的正常工作。那么, transparent 的作用究竟是什么?

  proxy /ray localhost:10000 {
    websocket
  }
  proxy /ray localhost:10000 {
    websocket
    transparent 
  }

Most helpful comment

文档说得很清楚

header_upstream sets headers to be passed to the backend. The field name is name and the value is value. This option can be specified multiple times for multiple headers, and dynamic values can also be inserted using request placeholders. By default, existing header fields will be replaced, but you can add/merge field values by prefixing the field name with a plus sign (+). You can remove fields by prefixing the header name with a minus sign (-) and leaving the value blank.

-Origin就是去掉Origin头,这么做显然是为了避免服务器对请求的同源检查(实际上会不会检查先不管)。这样你就可以随便设置websocket的header而不会被拒绝了。如果客户端不设置websocket的Origin头,这个配置自然用不到。

All 4 comments

直接去看caddy的官方文档不就好了吗?

@veekxt caddy 文档没说到。 header_upstream -Origin 这个组合基本上只出现在搭建 v2ray 的文章里。

文档说得很清楚

header_upstream sets headers to be passed to the backend. The field name is name and the value is value. This option can be specified multiple times for multiple headers, and dynamic values can also be inserted using request placeholders. By default, existing header fields will be replaced, but you can add/merge field values by prefixing the field name with a plus sign (+). You can remove fields by prefixing the header name with a minus sign (-) and leaving the value blank.

-Origin就是去掉Origin头,这么做显然是为了避免服务器对请求的同源检查(实际上会不会检查先不管)。这样你就可以随便设置websocket的header而不会被拒绝了。如果客户端不设置websocket的Origin头,这个配置自然用不到。

@veekxt 多谢解释。大概明白了。毕竟,我只是一个搞法律的.... ,没有你这个解释还真的不理解。

Was this page helpful?
0 / 5 - 0 ratings