Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot run node-red-docker behind nginx docker with virtual directory. #181

Open
huangchinlin opened this issue Jun 27, 2020 · 2 comments
Open

Comments

@huangchinlin
Copy link

What are the steps to reproduce?

install:

  1. ubuntu 20.04 desktop
  2. docker-ce 19.03.12
  3. node-red 1.0.6 (from latest docker)
  4. nginx docker
  5. launch a virtual directory named "form" and set proxy_pass to node-red container in nginx conf file.

What happens?

proxy_pass may work, but some static reference library cannot be located correctly.
image

I had tried to modify httpAdminRoot, httpNodeRoot, httpRoot, httpStatic in settings.js, seems not the correct setting item for this case.

nginx setting

upstream form {
  server form:1880;  <-- node-red container
}

server {
...
  location ~ ^/form(/?)(.*) {
    proxy_pass http://form/$2;
    proxy_http_version 1.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

  location / {
    ...  <- run other pages here.
  }
}
@CTGControls
Copy link
Contributor

CTGControls commented Jul 16, 2020

This is how I am do it. You will need to setup DNS for this to work

worker_processes 4;
events { worker_connections 1024; }
http {
    sendfile on;
    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_set_header   X-Forwarded-Host $server_name;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }


		server {
        listen 80;
        listen [::]:80;
        server_name www.nodered.SomeDomain.com;
        location / {
            resolver 127.0.0.11 valid=10s;
            set $upstreamName node_red:1880;
            proxy_pass         http://$upstreamName;
            proxy_redirect     off;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
        }
    }
}

Here Is my docker compose file:


################################################################################
# Node-RED Stack or Compose
################################################################################
# docker stack deploy node-red --compose-file docker-compose-node-red.yml
# docker-compose -f docker-compose-node-red.yml -p myNoderedProject up
################################################################################

version: '3.7'
services:
  node_red:
    image: nodered/node-red:latest-12
    restart: always
    environment:
      - TZ=	America/Chicago
    volumes:
      - node_red_data:/data
    ports:
      - 1880:1880
      - 55388:55388
      - 502:502
    stop_grace_period: 2m
    deploy:
      replicas: 1
      update_config:
        parallelism: 1
        delay: 1m
      restart_policy:
        condition: on-failure
      placement:
        constraints: [node.role == manager]
    depends_on:
      - timescaledb
    links:
      - timescaledb


networks:
  default:
    external:
      name: backend_network

volumes:
  node_red_data:
    external:
      name: node_red_data

@s4ke
Copy link

s4ke commented Sep 15, 2020

With some rewrite rules, you can achieve this pretty nicely (slightly modified from what we are running in production):

    location /nodered/comms {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        rewrite ^/nodered(.*)$ $1 break;
        proxy_pass_header               Set-Cookie;
        proxy_set_header                X-Real-IP $remote_addr;
        proxy_set_header                Host $http_host;
        proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header                X-NginX-Proxy true;
        proxy_pass_request_headers      on;
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   X-Forwarded-Proto $scheme;
        
        resolver 127.0.0.11 ipv6=off;

        proxy_pass         $noderedproxy;
    }

    location /nodered {
        rewrite ^(.*[^/])$ $1/ permanent;
    }

    location /nodered/ {
        rewrite ^/nodered(.*)$ $1 break;
        proxy_pass_header               Set-Cookie;
        proxy_set_header                X-Real-IP $remote_addr;
        proxy_set_header                Host $http_host;
        proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header                X-NginX-Proxy true;
        proxy_pass_request_headers      on;
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   X-Forwarded-Proto $scheme;
        
        resolver 127.0.0.11 ipv6=off;

        proxy_pass         $noderedproxy;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants