Multiple NodeRED instances behind Nginx Reverse proxy

Hi guys,

I'm preparing a stage in my fablab to teach NodeRED. As I want everyone has its own NodeRED instance, I created multiple instances on my Proxmox server. In front I have an Nginx virtual machine which manages HTTPS and serve the right server function of the URL (ex : 200.example.org => 192.168.9.200 201.example.org => 192.168.9.201 etc ...).

Problem : if I join a NodeRED instance, and after that I try to join another instance, I got a 502 bad gateway error (sometimes I loss both instances for a while).

I used another virtual machine directly on the Proxmox server (so on "local" network) and nodered instances are OK. All other services (other virtual machines) are OK, even when NodeRED instances are not joinable. So the issue seems to come from Nginx<->Here<->NodeRED.

Just to be clear : if I try to join a NodeRED instance => it's OK, I can refresh the page as I want everything is OK. If I try to join another instance, I can join this instance but the mess begins ...

Nginx server config (just one instance showed, others are just a copy/paste of that just changing the urls and names) :

server {

   listen 443  ssl http2;
   listen [::]:443 ssl http2;
   server_name 200.example.org;
   
   access_log  /var/log/nginx/200.access.log;
   
   ssl on;
   ssl_stapling on;
   ssl_stapling_verify on;
   ssl_certificate /etc/letsencrypt/live/200.example.org/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/200.example.org/privkey.pem;
   ssl_trusted_certificate /etc/letsencrypt/live/200.example.org/fullchain.pem;
   ssl_session_timeout 1d;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location ~ /\.well-known{
     root /var/www/html;
     allow all;
    }

 location / {
   proxy_pass http://192.168.9.200:2880;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr;
  }
}

Both Nginx and NodeRED installs are fresh.
Only modified files are : Nginx sites and settings.json for NodeRED (change port and add admin credentials).

error.log shows this :
2019/05/27 20:46:21 [error] 2367#2367: *684 connect() failed (113: No route to host) while connecting to upstream, client: 37.169.21.20, server: 201.example.org, request: "GET / HTTP/2.0", upstream: "http://192.168.9.201:2880/", host: "201.example.org"

I searched on Google of course but could not found any solutions ...
I also found this topic : 4 x Node-RED Docker containers with Nginx reverse proxy - help
But didn't help :s
So if someone can help me ... Thanks and regards :slight_smile:

The proxy_pass port is 2880 instead of 1880? (http://192.168.9.201:2880/) Using a non-standard port might be for a reason but just thought I'd point it out in case it was a typo.

Can you curl http://192.168.9.201:2880/ from the same box as nginx? The error seems pretty unambiguous - "can't connect, yo!" - but your message confused me a little as it seemed that the connection via nginx works initially then doesn't?

Thanks for your reply !

Late tonight I finally found the issue (on a russian website, thank you Google Translate :rofl:) : I don't know why but when I cloned my first virtual machine, it also cloned the MAC address (I cloned again and this time it generated a new MAC address, ?!). And two machines with the same MAC address on the same network, obviously ...

So sorry for your time, I hoped if someone meet the same issue this topic will help :slight_smile: