Centos7下使用nginx代理Node-RED,并实现密码访问

该博客介绍了如何在CentOS7系统中安装和配置Node-RED以实现开机自启动,并通过Nginx进行反向代理,包括设置HTTP和WebSocket的代理规则,以及启用基本认证的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 环境安装

(1)nodejs

(2)node-red

(3)pm2(开机自启动需要)

前面3个的安装请自行百度或参考博客

Centos7下实现Node-RED开机自启动、启用登录功能_小捣蛋1124的博客-CSDN博客

(4)nginx

yum install -y nginx

(5)密码生成工具

yum install -y httpd-tools

2. 配置

(1)修改settings.js的根路径

  • 文件路径:当前用户目录下.node-red/settings.js,

        例如/root/.node-red/settings.js

  • 参数修改

        httpAdminRoot: '/node-red'

  • 重启node-red

说明:重启后访问路径就为:http://127.0.0.1:1880/node-red

(2)nginx配置

location /node-red {
    proxy_pass http://127.0.0.1:1880;
    #auth_basic "Please input username and password";  
    #auth_basic_user_file /etc/nginx/conf.d/noderedpwd; 
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;
}

location /node-red/comms {
    proxy_pass http://127.0.0.1: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";
}

说明:
/node-red/comms:代理的是ws
/node-red:代理的是http

(3)如果需要启用密码配置

  • 用户密码密码生成
htpasswd -c -d /etc/nginx/conf.d/noderedpwd admin
或
htpasswd -bdc /etc/nginx/conf.d/noderedpwd admin 123456
  • 打开auth_basic和auth_basic_user_file的配置,密码文件路径要对应上

  •  密码文件格式
admin:uzpZjljZuNBfI

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值