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

随笔21小时前发布 神经小迷妹
2 0 0

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的配置,密码文件路径要对应上

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

 密码文件格式

admin:uzpZjljZuNBfI

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...