【问题标题】:Changing Domain on Node Red Raspberry PI在 Node Red Raspberry PI 上更改域
【发布时间】:2021-02-26 07:52:36
【问题描述】:

当我想通过 Brower 访问 Node Red 时,我键入 192.168.0.24:1880/ui/。 现在我只想到达 Node-Red 端,有一个类似于 website.test 的本地域。

我已经将我的端口从 1880 端口更改为 80。

我还将 /etc/hosts 文件编辑到 -> 192.168.0.24 website.test 但是当我测试它时,我无法使用此域访问 Node-Red 网站。

有谁知道如何做到这一点?

【问题讨论】:

  • 您试图从哪里访问编辑器?你在哪台机器上编辑/etc/hosts?另外,您以哪个用户身份运行 Node-RED?
  • 我在 Raspi 上设置了 Node-Red,它与我的电脑在同一个网络中。当我想用我的电脑访问我创建的 Node-Red 网站时,我输入 192.168.0.24:1880/ui/ 这样我就可以看到我的网站了。现在我想通过同一网络中任何其他设备的自定义域打开它。就像我已经可以使用 ip 一样。在 /etc/hosts 中,我只需编辑 IP,我可以使用它访问我想要的域旁边的想要的网站。我不知道哪个用户在 Node Red 上运行,但我可以看看
  • 你能把127.0.0.1 website.test绑定到/etc/hosts吗?

标签: dns node-red raspberry-pi4


【解决方案1】:

首先,要将 Node-RED 绑定到端口 80,您需要在 pi 上以 root 身份运行它。这是一个非常糟糕的主意,除非您 100% 了解后果,因为它会引发很多潜在的安全问题。

更好的解决方案是将 Node-RED 绑定的地址更改为 127.0.0.1,这样它就只在 localhost 上侦听,然后使用 nginx 之类的东西将其代理到端口 80。

您可以通过取消注释 userDir 中 settings.js 文件顶部的 uiHost 行来更改绑定地址(通常为 /home/pi/.node-red

基本的 nginx 配置如下所示:

server {
        listen 80;
        listen [::]:80;

        location / {
            proxy_pass http://127.0.0.1:1880;

        #Defines the HTTP protocol version for proxying
        #by default it it set to 1.0.
        #For Websockets and keepalive connections you need to use the version 1.1    
        proxy_http_version  1.1;

        #Sets conditions under which the response will not be taken from a cache.
        proxy_cache_bypass  $http_upgrade;

        #These header fields are required if your application is using Websockets
        proxy_set_header Upgrade $http_upgrade;

        #These header fields are required if your application is using Websockets    
        proxy_set_header Connection "upgrade";

        #The $host variable in the following order of precedence contains:
        #hostname from the request line, or hostname from the Host request header field
        #or the server name matching a request.    
        proxy_set_header Host $host;

        }
}

其次,在 pi 上编辑 /etc/hosts 文件只会映射在 pi 上运行的进程的主机名,而不是在任何地方(例如在您的电脑上)。

如果您的另一台机器是另一台 Linux 机器或 Mac,那么您可能可以使用 mDNS 访问 pi,默认情况下会在 raspberrypi.local 上找到它。不幸的是,Windows 不支持 mDNS,因此无法正常工作(您可以通过安装一些来自 Apple 的打印机包来添加支持)。

您可以在 Windows (C:\Windows\System32\drivers\etc\hosts) 上编辑主机文件,但这不是一个很好的解决方案,因为您需要对每台想要访问 Node-RED 实例的机器执行此操作。

其他选项包括在您的本地路由器上添加一个条目或运行您自己的 DNS 服务器,但这两个选项都太复杂了,无法在这里介绍。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-10
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    相关资源
    最近更新 更多