Caddy中websocket的写法

网上有很多方案都不能解决,最后不断测试,找到一个可行的写法。

以例说明,用二级域名分流

#分流地址
tt.abc.com {
#这些是入站协议header里的特征(应该还有其他也可以用),用于判断是websocket,
	@ws {
	    header Connection *Upgrade*
	    header Upgrade websocket
	}
	encode gzip
	#证书要和分流地址匹配
	tls ./abc.com.pem ./abc.com.key
	reverse_proxy @ws localhost:61235 {
        #转发后端http,取消tls验证
        transport http {
        	tls_insecure_skip_verify
		}
	}
	#不是websocket协议的,走这里
	resverse_proxy localhost:61234
}

官方文档中,

By default, Caddy passes thru incoming headers—including Host—to the backend without modifications, with three exceptions:
It sets or augments the X-Forwarded-For header field.
It sets the X-Forwarded-Proto header field.
It sets the X-Forwarded-Host header field.
For these X-Forwarded-* headers, by default, the proxy will ignore their values from incoming requests, to prevent spoofing.

翻译意思是:

默认情况下,Caddy会将传入的头信息(包括Host)无修改地传递给后端,但有三个例外:
它设置或增强了X-Forwarded-For头字段。
它设置了X-Forwarded-Proto头字段。
它设置了X-Forwarded-Host头字段。
对于这些X-Forwarded-*头,代理默认会忽略来自传入请求的它们的值,以防止欺骗。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值