Mchoeti
Mchoeti

Reputation: 536

Node Red - Lost Connection after redirection from port 1880 to a subdirectory

I have NodeRed installed on a VM with Cent OS 7.x and Apache 2.4.6 (CentOS).

If I open up the URL http://10.1.1.1:1880/ , everything is working. I can deploy nodes and see the debug. But I need Node Red on a special location. Next step was the configuration of a Proxy Pass in my httpd.conf .

Result: Node Red is available under http://10.1.1.1/nr/ . But after a few seconds I got the following error message.

Lost connection to server, reconnecting in 44s. Try now

Then I tried the same, also adding the port config to the 443, Result: Node Red is available underhttps://10.1.1.1/nr/ and it is working for a few seconds. Then the same error message ( + or – a few seconds) appear

Lost connection to server, reconnecting in 54s. Try now

Then I checked the Console in the Browser Error Code:

WebSocket connection to 'ws://10.1.1.1/nr/comms' failed: Error during WebSocket handshake: Unexpected response code: 404 a @ red.min.js:16

OK, it seems that this is a problem with the WebSocket. If someone have an idea, great because I tried different solutions added the Load Modules and have at the moment not really an idea. All the best.

ps: This is my proxy pass setting in the httpd.conf

<VirtualHost *:80>
  ServerName 10.1.1.1
  RewriteEngine On
  RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
  RewriteCond %{QUERY_STRING} transport=websocket    [NC]
  RewriteRule /(.*)           ws://localhost:1880/$1 [P,L]
  ProxyPass /nr/ http://127.0.0.1:1880/ timeout=360
  ProxyPassReverse /nr/ http://127.0.0.1:1880/
</VirtualHost>

Upvotes: 1

Views: 4511

Answers (3)

gmag11
gmag11

Reputation: 101

With Node-Red 1.0 if used this configuration

RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule .* "ws://localhost:1880%{REQUEST_URI}" [P]

ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:1880/
ProxyPassReverse / http://localhost:1880/

Using Rewrite engine makes websocket to work correcly. Meanwhile I've not got it to work if I use /nodered/ url instad of /

Upvotes: 0

Lu.Wi
Lu.Wi

Reputation: 71

I did it like this:

ProxyRequests off
ProxyPreserveHost on
ProxyPass               "/comms"        "ws://localhost:1880/comms"
ProxyPassReverse        "/comms"        "ws://localhost:1880/comms"
ProxyPass               "/"             "http://127.0.0.1:1880/"
ProxyPassReverse        "/"             "http://127.0.0.1:1880/"

<Proxy *>
  Order deny,allow
  Allow from all
</Proxy>

This solved the issue for me. If you have TLS enabled change ws: to wss:

Upvotes: 5

hardillb
hardillb

Reputation: 59668

I'm not sure what the RewriteRule is doing, but I think you need to be using the mod_proxy_wstunnel module and a ProxyPass rule like this:

ProxyPass "/nr/comms"  "ws://localhost:1880/comms"

Upvotes: 1

Related Questions