Node red shows Lost connection to server, reconnecting.. beacuse of WebSocket connection to 'wss:// comms' api failed

We have created node-red project and that deployed on staging environment, and it is work fine.

But after deploying on production It give following error.

We have checked node-red log and it is also fine,

On server log and browser shows issue with wss:// comms api that run internally by node-red.

We have allowed TCP on server for websocket but that also not work.

Something in your production environment is blocking the websocket. That's all we can say. If you're running behind a reverse proxy, make sure it allows websockets.

1 Like

we are using ingress controller load balancer where we have allowed tcp protocol in our listener.
-ingress config map data as follows

proxy-connect-timeout: "30"
proxy-protocol-header-timeout: "5"
proxy-read-timeout: "120"
proxy-send-timeout: "120"
real-ip-header: proxy_protocol
upstream-keepalive-connections: "1000"
use-forwarded-headers: "true"
use-proxy-protocol: "true"

Ok, so I have fixed the websocket issue.
Some context, I run node-red as embedded in an express server. All my express routes start with /api, so I have to config my settings of Node-RED to reflect that.
This is my settings. Notice the httpAdminRoot and httpNodeRoot.

const settings = {
      httpAdminRoot: '/api/red/admin/',
      httpNodeRoot: '/api/red/',
      userDir: `${os.homedir()}/.nodered/`,
      flowFile: './flows/flows.json',
      flowFilePretty: true,
      functionGlobalContext: {
        lodash: require('lodash'),
        mongodb: require('mongodb'),
      },
      editorTheme: {
        header: {
          title: 'Node-RED',
          image: null,
        },
      },
    };

    RED.init(server, settings);
    this.app.use(settings.httpAdminRoot, RED.httpAdmin);
    this.app.use(settings.httpNodeRoot, RED.httpNode);
    RED.start();

So in my nginx config, I took the code from Using NGINX as a WebSocket Proxy and change my config on the remote server to this.

    location /api/ {
        proxy_pass http://localhost:3000/api/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

Now I can access the node-red client at http://localhost:3000/api/red/admin/
Hope this help.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.