节点红色 - 从端口 1880 重定向到子目录后丢失连接

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

我在虚拟机上安装了 NodeRed Cent OS 7.x Apache 2.4.6 (CentOS).

如果我打开 URL http://10.1.1.1:1880/ ,一切正常。我可以部署节点并查看调试。但是我需要一个特殊位置的 Node Red。 下一步是在我的 httpd.conf 中配置代理通行证。

结果:红色节点在 http://10.1.1.1/nr/ 下可用。但几秒钟后我收到以下错误消息。

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

然后我尝试了同样的方法,也将端口配置添加到 443, 结果:Node Red 在 https://10.1.1.1/nr/ 下可用,并且它正在工作几秒钟。然后出现同样的错误信息(+或-几秒)

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

然后我查看了浏览器中的控制台 错误代码:

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

好的,看来是WebSocket的问题。 如果有人有想法,那很好,因为我尝试了不同的解决方案,添加了加载模块,但目前还没有真正的想法。祝一切顺利。

ps:这是我在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/ [P,L]
  ProxyPass /nr/ http://127.0.0.1:1880/ timeout=360
  ProxyPassReverse /nr/ http://127.0.0.1:1880/
</VirtualHost>

我不确定 RewriteRule 在做什么,但我认为您需要使用 mod_proxy_wstunnel 模块和这样的 ProxyPass 规则:

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

我是这样做的:

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>

这解决了我的问题。如果启用了 TLS,请将 ws: 更改为 wss:

如果使用此配置,则使用 Node-Red 1.0

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/

使用 Rewrite 引擎可以使 websocket 正常工作。同时,如果我使用 /nodered/ url 而不是 /

,我就无法使用它