问题1. ws://domain:8083/mqtt 在MQTT Client中可以连线,但是上web却无法成功连线
问题2. wss://domain:8084/mqtt 在MQTT Client中无法连线成功,但telnet domain 8084可以通,最终是希望使用wss://domain:8084/mqtt 上web要可以成功连线,目前没找到完整的技术文件来完成
环境与状况:
我在k8s中使用helm部署了ingress-nginx和emqx的服务,emqx 版本5.1.4、ingress-nginx版本1.21.6,ingress-nginx的svc使用LoadBalancer来放出外部IP,cinfigmap的是nginx的tcp来放出1883、8083、8084 port,domain则是部署emqx的ingress,
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-read-timeout: “3600”
nginx.ingress.kubernetes.io/proxy-send-timeout: “3600”
nginx.ingress.kubernetes.io/server-snippets: |
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Connection “upgrade”;
proxy_cache_bypass $http_upgrade;
}
manager: nginx-ingress-controller
operation: Update
subresource: status
name: emqx-ingress
namespace: emqx
spec:
defaultBackend:
service:
name: emqx
port:
number: 1883
ingressClassName: nginx
rules:
- host: domain
http:
paths:- backend:
service:
name: emqx
port:
number: 1883
path: /mqtt
pathType: Prefix - backend:
service:
name: emqx
port:
number: 18083
path: /
pathType: Prefix
tls:
- backend:
- secretName: letsencrypt-certificate-tls
目前已经能够让我telnet的到域名8083、8084 port,並且使用MQTTX的client工具能够连线到ws://domain:8083/mqtt,但提交给前端时却无法连接上,前端只能先使用ws://IP:8083/mqtt去做连线,而wss则是完全不知道如何做。
以下是使用域名在开发者工具中报的错误 (index.html)
mqtt.min.js:1 WebSocket connection to ‘ws://domain:8083/mqtt’ failed:
index.html:44 error
- Event
- isTrusted: true
- bubbles: false
- cancelBubble: false
- cancelable: false
- composed: false
- currentTarget: WebSocket {url: ‘ws://domain:8083/mqtt’, readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
- defaultPrevented: false
- eventPhase: 0
- returnValue: true
- srcElement: WebSocket {url: ‘ws://domain:8083/mqtt’, readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
- target: WebSocket {url: ‘ws://domain:8083/mqtt’, readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
- timeStamp: 1040.5
- type: “error”
- [[Prototype]]: Event