# Config Nginx as Node-RED load balancer

**URL:** <https://discourse.nodered.org/t/config-nginx-as-node-red-load-balancer/74835>\
**Category:** General\
**Tags:** docker\
**Created:** [7 February 2023 10:47 UTC](https://discourse.nodered.org/t/config-nginx-as-node-red-load-balancer/74835 "2023-02-07T10:47:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miladmrm](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@miladmrm](https://discourse.nodered.org/u/miladmrm)\
**Post date:** [7 February 2023 10:47 UTC](https://discourse.nodered.org/t/config-nginx-as-node-red-load-balancer/74835/1 "2023-02-07T10:47:44Z")

</div>

I have a docker-compose file as below:

```auto
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:

```auto
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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fdb1e27a3574f71f726e298dc09804cb3846d3e0.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 February 2023 19:33 UTC](https://discourse.nodered.org/t/config-nginx-as-node-red-load-balancer/74835/2 "2023-02-07T19:33:23Z")

</div>

> [@miladmrm](#):
>
> but nothing work, my mean that i can't read data from DB or even I can't inject the `inject node`

i dont have any experience with Nginx but doing a quick search on the forum  
[https://discourse.nodered.org/search?q=nginx](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

```auto
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 April 2023 19:34 UTC](https://discourse.nodered.org/t/config-nginx-as-node-red-load-balancer/74835/3 "2023-04-08T19:34:22Z")

</div>

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