“与服务器失去连接,12 秒后重新连接。立即尝试”节点红色错误

问题描述 投票:0回答:1

当通过配置了 SSL/TLS 加密的 Apache 反向代理访问 Node-RED 的 UI 时,我遇到了问题。设置如下:

Node-RED 在 http://localhost:1880 上本地运行。 Apache 用作反向代理,将来自公共域 (https://iot.example.com) 的请求转发到 Node-RED。 在 Apache 中配置 SSL/TLS 加密来处理传入的 HTTPS 请求。 通过公共域 (https://iot.example.com) 访问 Node-RED 的 UI 时会出现问题。尽管 UI 最初加载,但它经常显示“与服务器的连接丢失,正在重新连接”消息,然后尝试重新连接。

在查看 Apache 有关该问题的错误日志时,我注意到以下日志:

[Tue Mar 12 01:46:59.958983 2024] [socache_shmcb:debug] [pid 9299] mod_socache_shmcb.c(508): AH00831: socache_shmcb_store (0x21 -> subcache 1)
[Tue Mar 12 01:46:59.959094 2024] [socache_shmcb:debug] [pid 9299] mod_socache_shmcb.c(862): AH00847: insert happened at idx=0, data=(0:32)
[Tue Mar 12 01:46:59.959114 2024] [socache_shmcb:debug] [pid 9299] mod_socache_shmcb.c(865): AH00848: finished insert, subcache: idx_pos/idx_used=0/1, data_pos/data_used=0/212
[Tue Mar 12 01:46:59.959132 2024] [socache_shmcb:debug] [pid 9299] mod_socache_shmcb.c(530): AH00834: leaving socache_shmcb_store successfully
[Tue Mar 12 01:46:59.960120 2024] [ssl:debug] [pid 9299] ssl_engine_kernel.c(415): [client 74.12.48.208:2255] AH02034: Initial (No.1) HTTPS request received for child 2 (server iot.example.com:443)
[Tue Mar 12 01:46:59.960214 2024] [authz_core:debug] [pid 9299] mod_authz_core.c(843): [client 74.12.48.208:2255] AH01628: authorization result: granted (no directives)
[Tue Mar 12 01:46:59.960309 2024] [proxy:debug] [pid 9299] mod_proxy.c(1503): [client 74.12.48.208:2255] AH01143: Running scheme http handler (attempt 0)
[Tue Mar 12 01:46:59.960333 2024] [proxy:debug] [pid 9299] proxy_util.c(2531): AH00942: http: has acquired connection for (localhost)
[Tue Mar 12 01:46:59.960355 2024] [proxy:debug] [pid 9299] proxy_util.c(2587): [client 74.12.48.208:2255] AH00944: connecting http://localhost:1880/comms to localhost:1880
[Tue Mar 12 01:46:59.960376 2024] [proxy:debug] [pid 9299] proxy_util.c(2810): [client 74.12.48.208:2255] AH00947: connected /comms to localhost:1880
[Tue Mar 12 01:46:59.960726 2024] [proxy:debug] [pid 9299] proxy_util.c(3111): AH00951: http: backend socket is disconnected.
[Tue Mar 12 01:46:59.961074 2024] [proxy:debug] [pid 9299] proxy_util.c(3267): (111)Connection refused: AH00957: http: attempt to connect to [::1]:1880 (localhost) failed
[Tue Mar 12 01:46:59.962089 2024] [proxy:debug] [pid 9299] proxy_util.c(3276): AH02824: http: connection established with 127.0.0.1:1880 (localhost)
[Tue Mar 12 01:46:59.962192 2024] [proxy:debug] [pid 9299] proxy_util.c(3462): AH00962: http: connection complete to [::1]:1880 (localhost)
[Tue Mar 12 01:46:59.965368 2024] [proxy:debug] [pid 9299] proxy_util.c(2546): AH00943: http: has released connection for (localhost)
[Tue Mar 12 01:47:00.007071 2024] [ssl:info] [pid 9299] SSL Library Error: error:0A000126:SSL routines::unexpected eof while reading
[Tue Mar 12 01:47:00.007147 2024] [ssl:info] [pid 9299] [client 74.12.48.208:2255] AH01998: Connection closed to child 2 with abortive shutdown (server iot.example.com:443)

我已确保 Node-RED 正在运行并可在 http://localhost:1880 上访问,并且 Apache 服务器已正确配置为处理 SSL/TLS 连接。此外,没有防火墙限制阻止 Apache 和 Node-RED 之间的通信。

这里是使用代理的相关apache配置文件:

<VirtualHost *:443>
       
        ServerName iot.example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/IoT

        SSLProxyEngine On
        ProxyPreserveHost On
        ProxyRequests Off
        ProxyPass /comms wss://localhost:1880/comms/ disablereuse=On
        ProxyPass / http://localhost:1880/
        ProxyPassReverse /comms wss://localhost:1880/comms/
        ProxyPassReverse / http://localhost:1880/


        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

        ErrorLog ${APACHE_LOG_DIR}/IoT.log
        CustomLog ${APACHE_LOG_DIR}/IoT_access.log combined
        
        SSLEngine on
        SSLCertificateFile /root/.acme.sh/iot.example.com_ecc/fullchain.cer
        SSLCertificateKeyFile /root/.acme.sh/safwanshaib.com_ecc/iot.example.com.key
</VirtualHost>

node-red settings.js 文件:

module.exports = {
    flowFile: 'flows.json',
    flowFilePretty: true,
    uiPort: process.env.PORT || 1880,
    diagnostics: {
        enabled: true,
        ui: true,
    },
    runtimeState: {
        enabled: false,
        ui: false,
    },
    logging: {
        console: {
            level: "info",
            metrics: false,
            audit: false
        }
    },
    exportGlobalContextKeys: false,
    externalModules: {
    },
    editorTheme: {
        palette: {
        },
        projects: {
            enabled: false,
            workflow: {
                mode: "manual"
            }
        },
        codeEditor: {
            lib: "monaco",
            options: {
            }
        },
        markdownEditor: {
            mermaid: {
                enabled: true
            }
        },
    },
    functionExternalModules: true,

    functionTimeout: 0,

    functionGlobalContext: {
    },
    ui: {
        httpRoot: '/',
        httpAdminRoot: '/',
    },
    debugMaxLength: 1000,
    mqttReconnectTime: 15000,
    serialReconnectTime: 15000,
}

我尝试更新和升级 sys 包(包括 Node.js),但没有成功,出现连接错误。

什么可能导致此问题,如何排除故障并解决它?任何见解或建议将不胜感激。

apache ubuntu server proxy node-red
1个回答
0
投票

您不应该使用

wss://
连接到本地红色节点,因为它不使用 HTTPS/TLS

        ProxyPass /comms ws://localhost:1880/comms disablereuse=On
        ProxyPass / http://localhost:1880/
        ProxyPassReverse /comms ws://localhost:1880/comms
        ProxyPassReverse / http://localhost:1880/

您还应该从通信路径中删除尾随的

/

© www.soinside.com 2019 - 2024. All rights reserved.