我的设置如下。我们在ECS群集上运行ECS(AWS)和服务。我们最近部署了一项支持REST终结点和WebSocket的服务。 REST API可以正常工作。问题在于建立WebSocket连接。在Application Load Balancer和服务之间,我们设置了Traefik(v1.7),用于在请求到达服务之前将请求代理到服务并剥离部分url。
请求流程如下:
Client <--- (wss/https) ---> ALB (AWS) - SSL offloading <--- (ws/http) ---> Traefik <--- (ws/http) ---> Service
我尝试将服务直接注册到AWS中的ALB,并且可以建立WebSocket连接,因此这意味着Traefik中的某些内容并未将WebSocket连接代理到该服务。我已经搜索了Traefik和WebSocket的所有问题,但主要的答案是您不需要配置Traefik即可与WebSockets一起使用,它是开箱即用的。我通过向容器传递额外的标签尝试了各种设置,但似乎没有任何效果。
这是我要传递给此特定服务的标签。对于此特定服务,我添加了traefik.wss.protocol: "http"
和traefik.backend.loadbalancer.stickiness: "true"
,但没有帮助。对于仅使用http
的其他服务,该配置有效,而无需添加这两个额外的配置。
traefik.frontend.rule:
Fn::Sub: "PathPrefixStrip: /${ServiceName}"
traefik.enable: "true"
traefik.protocol: "http"
traefik.wss.protocol: "http" <---------------------- ADDED
traefik.backend.loadbalancer.method: "wrr"
traefik.backend.loadbalancer.stickiness: "true" <--- ADDED
traefik.backend.healthcheck.path: "/health"
traefik.backend.healthcheck.interval: "10s"
我的Traefik配置:
debug = true
logLevel = "DEBUG"
defaultEntryPoints = ["http", "https"]
[accessLog]
[entryPoints]
[entryPoints.http]
address = ":80"
compress = true
[entryPoints.webadmin]
dashboard = true
address = ":8080"
[entryPoints.webadmin.auth]
[entryPoints.webadmin.auth.basic]
users = ["BASIC_AUTH"]
[entryPoints.https]
address = ":443"
[entryPoints.https.redirect]
entryPoint = "http"
[file]
watch = true
[metrics]
[metrics.influxdb]
address = "INFLUXDB_HOST:INFLUXDB_PORT"
pushinterval = "10s"
[api]
entryPoint = "webadmin"
[ping]
entryPoint = "http"
[lifeCycle]
requestAcceptGraceTimeout = "10s"
[ecs]
clusters = ["CLUSTER_HOST"]
watch = true
domain = "DOMAIN"
autoDiscoverClusters = false
refreshSeconds = 15
exposedByDefault = false
region = "AWS_REGION"
我是否缺少某些配置,还是必须进行很多配置,尤其是在容器级别?