Node-red环境搭建及Nginx代理,添加用户名及密码

一、环境准备,NodeJs安装

nodejs不是本文的重点,略过

二、Node-red安装

1、我们的安装环境是centos7
2、执行如下命令安装

cnpm install -g node-red

3、户动

node-red

http://127.0.0.1:1880便可以访问Node-RED的前台界面,进行编程
但现在的情况是,不需要密码便能访问,这样对外网及不安全,所以我们通过nginx代理转发,加用户名及密码验证,如果不需要此功能的,可不往下看
4、修改node-red访问的根路径为/node-red

cd  #进入当前用户的根路径
ls -al

dr-xr-x---. 13 root root  4096 Aug 11 10:14 .
dr-xr-xr-x. 21 root root  4096 Jul 16 15:04 ..
-rw-r--r--   1 root root 15955 Aug 11 11:13 .bash_history
-rw-r--r--.  1 root root    18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root   176 Dec 29  2013 .bash_profile
drwxr-xr-x   3 root root  4096 Aug 11 10:12 .node-gyp
drwxr-xr-x   4 root root  4096 Aug 11 11:12 .node-red

可以看到.node-red的目录,注意有个点

cd .node-red
vim settings.js

关键地方修改

httpAdminRoot: '/node-red',

这个时间重启,访问路径就变为:http://127.0.0.1:1880/node-red,有了根路径,方便nginx代理

三、nginx 代理配置

1、nginx安装

yum -y install nginx
yum  -y install httpd-tools

2、密码配置,添加用户名为admin的,然后输入密码为admin

htpasswd  -c -d /etc/nginx/conf.d/passwd admin
cd /etc/nginx/conf.d/
vim  default.conf

3、nginx配置如下

location /node-red/comms {
        proxy_pass http://server15:1880;
        proxy_read_timeout 300s;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;             
        proxy_set_header Connection "upgrade";
    }
location /node-red {
        proxy_pass http://node-red安装的机器ip:1880;
        auth_basic "Please input username and password";  
        auth_basic_user_file /etc/nginx/conf.d/passwd; 
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
    }

说明:
/node-red/comms:代理的是ws
/node-red:代理的是http
现在就可以通过如下地址进行访问,并要求输入用户名及密码admin/admin

http://ip:nginx的端口/node-red
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要设置Node-RED的登录页面,首先需要在设置文件settings.js中修改httpAdminRoot的值为"node-red",这将成为登录页面的根路径。然后,为了实现Node-RED识别图片内容,需要下载并安装一个名为node-red-dashboard的控件。在Node-RED的界面中,点击左上角的设置图标,并找到节点管理。在节点管理中,搜索并安装node-red-dashboard控件。等待下载完成后,就可以开始使用了。如果您想设置登录密码,在终端中运行命令“htpasswd -bdc /etc/nginx/conf.d/noderedpwd admin 123456”。这将创建一个名为node-redpwd的文件,并设置用户名为"admin",密码为"123456"。根据以上步骤,您可以成功设置Node-RED的登录页面。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Node-RED启用登录的2种方式](https://blog.csdn.net/james112496/article/details/124462478)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Node-Red-访客、操作员和管理员登录](https://blog.csdn.net/weixin_43195420/article/details/126966018)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值