# Websocket "'502 Bad Gateway' caused by: dial tcp connect: connection refused"

**URL:** <https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [January 27, 2021, 10:15am UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465 "2021-01-27T10:15:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![haikalrios](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/haikalrios/32/3002_2.png) [@haikalrios](https://community.traefik.io/u/haikalrios)\
**Post date:** [January 27, 2021, 10:15am UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/1 "2021-01-27T10:15:48Z")

</div>

I'm trying to make a websocket application work on Traefik 2.3, but when I send request to traefik I get 502 as following.

```auto
time="2021-01-27T10:08:17Z" level=debug msg="vulcand/oxy/roundrobin/rr: begin ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/json\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Connection\":[\"Upgrade\"],\"Origin\":[\"http://localhost:4443\"],\"Sec-Websocket-Extensions\":[\"permessage-deflate; client_max_window_bits\"],\"Sec-Websocket-Key\":[\"nbMGA+vLk//P91QRwUi5rQ==\"],\"Sec-Websocket-Version\":[\"13\"],\"Upgrade\":[\"websocket\"],\"X-Forwarded-Host\":[\"localhost:4443\"],\"X-Forwarded-Port\":[\"4443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"26d62bbceae5\"],\"X-Real-Ip\":[\"172.19.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:4443\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.19.0.1:57154\",\"RequestURI\":\"/json\",\"TLS\":null}"
time="2021-01-27T10:08:17Z" level=debug msg="vulcand/oxy/roundrobin/rr: Forwarding this request to URL" ForwardURL="http://9cc6620bf077:4441" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/json\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Connection\":[\"Upgrade\"],\"Origin\":[\"http://localhost:4443\"],\"Sec-Websocket-Extensions\":[\"permessage-deflate; client_max_window_bits\"],\"Sec-Websocket-Key\":[\"nbMGA+vLk//P91QRwUi5rQ==\"],\"Sec-Websocket-Version\":[\"13\"],\"Upgrade\":[\"websocket\"],\"X-Forwarded-Host\":[\"localhost:4443\"],\"X-Forwarded-Port\":[\"4443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"26d62bbceae5\"],\"X-Real-Ip\":[\"172.19.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:4443\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.19.0.1:57154\",\"RequestURI\":\"/json\",\"TLS\":null}"
time="2021-01-27T10:08:17Z" level=debug msg="'502 Bad Gateway' caused by: dial tcp 172.19.0.3:4441: connect: connection refused"
time="2021-01-27T10:08:17Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/json\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\",\"RawFragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Connection\":[\"Upgrade\"],\"Origin\":[\"http://localhost:4443\"],\"Sec-Websocket-Extensions\":[\"permessage-deflate; client_max_window_bits\"],\"Sec-Websocket-Key\":[\"nbMGA+vLk//P91QRwUi5rQ==\"],\"Sec-Websocket-Version\":[\"13\"],\"Upgrade\":[\"websocket\"],\"X-Forwarded-Host\":[\"localhost:4443\"],\"X-Forwarded-Port\":[\"4443\"],\"X-Forwarded-Proto\":[\"https\"],\"X-Forwarded-Server\":[\"26d62bbceae5\"],\"X-Real-Ip\":[\"172.19.0.1\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:4443\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"172.19.0.1:57154\",\"RequestURI\":\"/json\",\"TLS\":null}"

```

My route is

```auto
[http.routers]
  [http.routers.wss-server-server]
    rule = "Host(`localhost`)"
    service = "wss-server"
	middlewares = [
       "midleware-chain-websocket"
    ]
    tls=true
	entrypoints = [
      "wss"
    ]
  
[http.services]
  [http.services.wss-server.loadBalancer]
	passHostHeader = false
    [[http.services.wss-server.loadBalancer.servers]]
      url = "http//:myserverwss:4441"
    

```

my midleware only put X-forward

```auto
  [http.middlewares.midleware-chain-websocket.chain]
    middlewares = ["websocket-midleware-headers"]

  [http.middlewares.websocket-midleware-headers.headers.customRequestHeaders]
	X-Forwarded-Proto = ["https"]

```

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [January 27, 2021, 1:25pm UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/2 "2021-01-27T13:25:10Z")

</div>

The server you have defined is refusing the connection. Investigate why that service is refusing connections.

---

<div class="post-metadata">

**Author:** ![haikalrios](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/haikalrios/32/3002_2.png) [@haikalrios](https://community.traefik.io/u/haikalrios)\
**Post date:** [January 27, 2021, 3:20pm UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/3 "2021-01-27T15:20:06Z")

</div>

when I use a client socket outside of traefik it works fine, maybe my configuration in traefik is not correct.

The same client cannot connect when I use the traefik route.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [January 27, 2021, 4:37pm UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/4 "2021-01-27T16:37:03Z")

</div>

> [@haikalrios](#):
>
> `dial tcp 172.19.0.3:4441: connect: connection refused`

This says the connection is being actively refused. Does this server required extra configuration. Is it actually bound on the referenced ip address. Does it have its own logs to see what happens to the connection.

Standalone is it using https? You service url is plain http.

---

<div class="post-metadata">

**Author:** ![haikalrios](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/haikalrios/32/3002_2.png) [@haikalrios](https://community.traefik.io/u/haikalrios)\
**Post date:** [January 27, 2021, 5:28pm UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/5 "2021-01-27T17:28:19Z")

</div>

> [@cakiwi](#):
>
> Standalone is it using https? You service url is plain http.

It was an attempt.

I put the websocket server in trace log mode, but nothing. I'll try another way, but I have no idea

---

<div class="post-metadata">

**Author:** ![copolycube](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/copolycube/32/5060_2.png) [@copolycube](https://community.traefik.io/u/copolycube)\
**Post date:** [March 17, 2022, 2:01pm UTC](https://community.traefik.io/t/websocket-502-bad-gateway-caused-by-dial-tcp-connect-connection-refused/9465/6 "2022-03-17T14:01:42Z")

</div>

Hello @haikalrios , did you find a solution to your problem ? I seem to be hitting the same issue on my docker-compose projects (cf. [502 Bad Gateway' caused by: dial tcp 172.30.0.8:29091: connect: connection refused"](https://community.traefik.io/t/502-bad-gateway-caused-by-dial-tcp-172-30-0-8-connect-connection-refused/13789) )
