Caddy as reverse proxy for multiple node-red instances

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

a. System environment:

caddy running on Ubuntu 20.04 with systemd

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

{
    auto_https off
}
http://nzb.luytsm.be {
    reverse_proxy 192.168.0.25:6789
}

http://ha.luytsm.be {
    reverse_proxy 192.168.0.25:8123
}
http://home.luytsm.be {
    reverse_proxy 192.168.0.25:22
}
http://plex.luytsm.be {
    reverse_proxy 192.168.0.25:32400
}
http://nr.luytsm.be {
    reverse_proxy 192.168.0.25:1880
}
http://iote-one.luytsm.be/ {
    reverse_proxy 192.168.0.25:8881 {
    }
}
http://iote-two.luytsm.be/ {
    reverse_proxy 192.168.0.25:8882
}
http://iote-three.luytsm.be/ {
    reverse_proxy 192.168.0.25:8883
}
http://iote-four.luytsm.be/ {
    reverse_proxy 192.168.0.25:8884
}
http://iote-five.luytsm.be/ {
    reverse_proxy 192.168.0.25:8885
}
http://iote-six.luytsm.be/ {
    reverse_proxy 192.168.0.25:8886
}
http://iote-seven.luytsm.be/ {
    reverse_proxy 192.168.0.25:8887
}
http://iote-eight.luytsm.be/ {
    reverse_proxy 192.168.0.25:8888
}


3. The problem I’m having:

I am running 8 Node Red instances as an container with docker. I am trying to expose the docker containers to the internet. When I try to access the containers from their URL as described in the Caddyfile the pages wont load completely. I receive a blank page in my browser. But I can see the neccesary files when inspecting the webpage. When I navigate to Node Red containers with their IP and port they load completely .

4. Error messages and/or full log output:

I receive the following data when inspecting the

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<!--
  Copyright JS Foundation and other contributors, http://js.foundation

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<title>Node-RED</title>
<link rel="icon" type="image/png" href="favicon.ico">
<link rel="mask-icon" href="red&#x2F;images&#x2F;node-red-icon-black.svg" color="#8f0000">
<link rel="stylesheet" href="vendor/jquery/css/base/jquery-ui.min.css">
<link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="red/style.min.css">
</head>
<body spellcheck="false">
<div id="red-ui-editor"></div>
<script src="vendor/vendor.js"></script>
<script src="red&#x2F;red.min.js"></script>
<script src="red&#x2F;main.min.js"></script>

</body>
</html>

5. What I already tried:

I am able to run one node red instance with default port and a reverse proxy.
I think a solution would be to alter the used port of all the node red instances but this option is not scalable.

I want to be able to quickly destroy and create instances because this will be used by students in my class

6. Links to relevant resources:

a. Dockerfile

FROM nodered/node-red
RUN npm install node-red-dashboard node-red-contrib-ring-buffer

COPY settings.js /data/settings.js
COPY flows.json /data/flows.json

b. docker-compose.yml

version: "3.2"
services:
  node-red:
    build: .
    ports:
      - 8880-8888:1880

docker-compose up --scale node-red=8 -d

This is because you have trailing / in your site addresses. This gets handled as a path matcher. In Caddy v2, path matching is exact, so this means that it will only match on exactly / and not /foo. So just remove the trailing slash from all of your site blocks.

In other words, change http://iote-one.luytsm.be/ to http://iote-one.luytsm.be

This topic was automatically closed after 30 days. New replies are no longer allowed.