【问题标题】:Node Red - Lost Connection after redirection from port 1880 to a subdirectory节点红色 - 从端口 1880 重定向到子目录后丢失连接
【发布时间】:2019-10-28 05:15:16
【问题描述】:

我在具有 Cent OS 7.xApache 2.4.6 (CentOS) 的 VM 上安装了 NodeRed

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

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

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

然后我尝试了同样的方法,还将端口配置添加到 443, 结果:节点 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/$1 [P,L]
  ProxyPass /nr/ http://127.0.0.1:1880/ timeout=360
  ProxyPassReverse /nr/ http://127.0.0.1:1880/
</VirtualHost>

【问题讨论】:

  • 使用您在 apache 配置中的代理通行证设置编辑问题。这很可能是因为您没有启用 WebSocket 代理。

标签: apache centos node-red


【解决方案1】:

我是这样做的:

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:

【讨论】:

  • 谢谢。我不需要引号并将&lt;Location /&gt;Require all granted&lt;/Location&gt; 用于Apache 2.4,而ProxyPass*&lt;Location&gt; 之外使用,就像您一样。我在 Apache 终止了 TLS,但随后 http://ws:// 终止了本地服务。使用http://wss://(不匹配)让我遇到500 错误。
【解决方案2】:

我不确定RewriteRule 在做什么,但我认为您需要使用mod_proxy_wstunnel 模块和ProxyPass 规则,如下所示:

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

【讨论】:

  • 去掉了引号,在httpd中添加了Proxy Pass,去掉了RewriteEngine,保存,重启服务就好了。有效。谢谢
【解决方案3】:

如果使用此配置,则使用 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/

使用重写引擎使 websocket 能够正常工作。同时,如果我使用 /nodered/ url instad of /

,我将无法正常工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    相关资源
    最近更新 更多