Accessing Node-RED
- Mở trình duyệt của bạn và truy cập:
https://<SERVER_IP> - Cảnh báo SSL của trình duyệt (chứng chỉ tự ký) là điều bình thường.
- Cần xác thực (Cửa sổ bật lên Xác thực cơ bản)
- Phương thức xác thực: Xác thực cơ bản HTTP
- Thông tin đăng nhập được lưu trữ an toàn tại:
/root/.cloudzy-creds
Các tập tin và thư mục quan trọng
- Main installation directory is
/root/node-red. - Docker orchestration file is
/root/node-red/docker-compose.yml. - Persistent Node-RED data is stored in
/var/lib/docker/volumes/node-red_node-red-data/_data. - Nginx configuration file is located at
/etc/nginx/sites-available/node-red. - Basic authentication credentials are stored in
/etc/nginx/auth/node-red.htpasswd. - TLS certificates are stored in
/etc/nginx/ssl.
Quản lý dịch vụ
Kiểm tra trạng thái container:
docker ps
Xem nhật ký:
docker compose -f /root/node-red/docker-compose.yml logs -f
Restart Node-RED:
docker compose -f /root/node-red/docker-compose.yml restart
Khởi động lại Nginx:
systemctl restart nginx
Node-RED Admin User (Alternative to Basic Auth)
Node-RED has its own internal authentication system, which can replace HTTP Basic Auth.
1. Locate settings.js
The main configuration file is inside the Node-RED Docker volume: /var/lib/docker/volumes/node-red_node-red-data/_data/settings.js
2. Enable adminAuth
Mở settings.js and uncomment (or add) the adminAuth section. It should look something like this:
adminAuth: {
type: "credentials",
users: [
{
username: "admin",
password: "<HASHED_PASSWORD>",
permissions: "*"
}]
},
3. Generate a password hash
You can generate the hash from inside the Node-RED container:
docker exec -it node-red-node-red-1 node-red admin hash-pw
You will be prompted to enter your plain password.
Copy the resulting hash and paste it as the password value in settings.js.
4. Restart Node-RED
After editing settings.js:
docker compose -f /root/node-red/docker-compose.yml restart
5. Disable HTTP Basic Auth in Nginx (Optional)
Edit the Nginx site file: /etc/nginx/sites-available/node-red
Remove or comment out these lines:
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/auth/node-red.htpasswd;
Khởi động lại Nginx:
systemctl restart nginx
Kích hoạt SSL với tên miền
1. Trỏ tên miền của bạn đến địa chỉ IP của máy chủ.
2. Chỉnh sửa cấu hình Nginx và thay thế cả hai server_name <IP>; với tên miền của bạn (<your-domain>) cho cả khối HTTP (cổng 80) và HTTPS (cổng 443):
vim /etc/nginx/sites-available/node-red
3. Cài đặt Certbot:
apt install -y certbot python3-certbot-nginx
4. Chạy lệnh sau để tạo chứng chỉ Let's Encrypt hợp lệ:
certbot certonly --nginx --non-interactive --agree-tos --email [email protected] -d yourdomain.com
5. Thay thế đường dẫn SSL trong cấu hình Nginx:
vim /etc/apache2/sites-available/node-red
# Before:
# ssl_certificate /etc/nginx/ssl/fullchain.pem;
# ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# After:
# ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
6. Khởi động lại Nginx để áp dụng các thay đổi:
systemctl restart nginx
7. Mở trình duyệt của bạn và truy cập: https://yourdomain.com