Config Nginx as Node-RED load balancer

I have a docker-compose file as below:

version: '2.2'

networks:
  Platform-Network:
    name: IoT-Network

volumes:
  Platform:
  MQTT-broker:
  DataBase:
  Nginx:

services: 

  Platform:
    image: custom-node-red:latest
    networks:
      - Platform-Network
    restart: always
    volumes:
      - ./node-red:/data
  
  MQTT-broker:
    container_name: mosquitto
    image: eclipse-mosquitto
    ports:
      - "192.168.100.101:1883:1883"
    networks:
      - Platform-Network
    restart: always
    depends_on:
      - Platform
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log 
  
  DataBase:
    container_name: mongodb
    image: mongo
    ports:
      - "8083:27017"
    networks:
      - Platform-Network
    restart: always
    depends_on:
      - Platform
    volumes:
      - ./mongodb/data:/data/db
      - ./mongodb/backup:/data/backup
      - ./mongodb/mongod.conf:/etc/mongod.conf
      - ./mongodb/log:/var/log/mongodb/

  Nginx:
    container_name: nginx
    image: nginx
    ports: 
      - "4000:4000"
    depends_on:
      - Platform
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    restart: always
    networks:
      - Platform-Network

and Nginx config file is:

user nginx;
events {
    worker_connections 1000;
}
http {
    upstream platform {
        server platform_Platform_1:1880;
        server platform_Platform_2:1880;
        server platform_Platform_3:1880;
    }
    server {
        listen [::]:4000;
        listen 4000;
        location / {
            proxy_pass http://platform;
        }
    }
}

I run services by docker-compose -f platform.yaml up -d --scale Platform=3
All containers up and I can connect to localhost:4000 and see Node-RED and even see my uibuilder, but nothing work, my mean that i can't read data from DB or even I can't inject the inject node. As shown in the image below, the inject and debug nodes seem to have disappeared and cannot be run.
Screenshot from 2023-02-07 14-06-09

i dont have any experience with Nginx but doing a quick search on the forum
https://discourse.nodered.org/search?q=nginx
you'll find several articles and examples of Nginx configurations.

Possibly the problem you are seeing is because the websockets that the Node-red Editor needs, is being blocked ? Have you checked your Browser's Dev tools ?

Several of the examples in the forum have these additional config lines for websockets

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.