WebSocket connection to 'wss://emqx.domain.com:8084/mqtt' failed

121 Views Asked by At

why websocket client is not able to connect to my emqx server? I am using the aws ec2 instance. in which I run two containers caddy and emqx. I have used Caddy as a reverse proxy to forward all the requests to emqx. I am able to open the emqx dashboard on emqx.domain.com. but when I go to the Diagnose section and try to connect to websocket client, it shows a pop-up "" when I click on the connect button. when I inspect the page and open a console it's showing "WebSocket connection to 'wss://emqx.domain.com:8084/mqtt' failed".

I have mapped my server IP to the domain name emqx.domain.co

When I disable the caddy proxy

when I open port 18083 on the ec2 security group
78.34.23.434 - opens emqx dashboard

When I open port 18083,8083 
78.34.23.434 - opens emqx dashboard and websocket client connected using websocket protocol

When I open ports 18083,8083,8084
78.34.23.434 - opens emqx dashboard and websocket client connected using websocket protocol, but not connected using websocket-secure protocol.

when i enable the caddy proxy

When I open ports 18083,8083,8084
78.34.23.434 - opens emqx dashboard but not connected using websocket-secure and websocket protocol.

Caddyfile:

emqx.domain.com {
  reverse_proxy emqx:18083
}
was://emqx.domain.com:8084/mqtt {
  reverse_proxy emqx:8084
}

docker-compose-caddy.yml

version: '3'
services:
  caddy:
    image: caddy:2.2.1-alpine
    container_name: caddy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./site:/srv
      - ./caddy_config:/config
      - ./caddy_data:/data
      - ./Caddyfile:/etc/caddy/Caddyfile

docker-compose-emqx.yml

version: '3'
services:
  emqx:
    image: emqx/emqx
    container_name: emqx
    restart: always
    volumes:
      - ./data:/opt/emqx/data
      - ./log:/opt/emqx/log
    environment:
      - EMQX_NAME=emqx
      - EMQX_LISTENER__TCP__EXTERNAL=1883
      - EMQX_LOADED_PLUGINS="emqx_management,emqx_dashboard,emqx_bridge_mqtt,emqx_sn"
      - EMQX_LISTENER__TCP__EXTERNAL=8883 # Add another listener for SSL/TLS
      - EMQX_LISTENER__WEBSOCKET__EXTERNAL=8083 # Add a WebSocket listener
      - EMQX_LISTENER__WEBSOCKET_SECURE__EXTERNAL=8084
    ports:
      - 1883:1883       #TCP
      - 8083:8083       #WEBSOCKET
      - 8084:8084       #WEBSOCKET_SECURE
      - 8883:8883       #SSL/TSL
      - 18083:18083     #DASHBOARD

I want to connect my websocket client to my emqx server. please help me solve this error. Are there any free open-source alternatives for emqx??

0

There are 0 best solutions below