Caddy install with localhost subdomain in http issue

Hi, I’m trying to install n8n locally through docker and proxy it with caddy. I get connection refused from :5678

Caddy file

http://hello.digicirco.localhost {
	respond "Hello, world!"
}

http://n8n.digicirco.localhost {
    reverse_proxy localhost:5678 {
      flush_interval 10
    }
}

and docker config

  caddy:
    container_name: caddy
    build: 
      context: docker/caddy
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
    networks:
      - frontend
      - backend

  n8n:
    container_name: n8n
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - DOMAIN_NAME=digicirco.localhost
      - SUBDOMAIN=n8n
      - GENERIC_TIMEZONE=Europe/Brussels
    volumes:
      - .data/.n8n:/home/node/.n8n # cannot change .data to
    networks:
      - backend

http://hello.digicirco.localhost/ is ok but http://n8n.digicirco.localhost/ gives a 502 from caddy. Log :

JSON Pretty Print
 
{
  "level": "error",
  "ts": 1645290573.478267,
  "logger": "http.log.error",
  "msg": "dial tcp 127.0.0.1:5678: connect: connection refused",
  "request": {
    "remote_addr": "192.168.96.1:58598",
    "proto": "HTTP/1.1",
    "method": "GET",
    "host": "n8n.digicirco.localhost",
    "uri": "/",
    "headers": {
      "Sec-Ch-Ua": [
        "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\""
      ],
      "Sec-Fetch-Site": [
        "none"
      ],
      "Upgrade-Insecure-Requests": [
        "1"
      ],
      "User-Agent": [
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
      ],
      "Accept": [
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
      ],
      "Accept-Encoding": [
        "gzip, deflate, br"
      ],
      "Accept-Language": [
        "en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7"
      ],
      "Sec-Ch-Ua-Platform": [
        "\"macOS\""
      ],
      "Cache-Control": [
        "max-age=0"
      ],
      "Sec-Fetch-Mode": [
        "navigate"
      ],
      "Sec-Fetch-User": [
        "?1"
      ],
      "Sec-Fetch-Dest": [
        "document"
      ],
      "Connection": [
        "keep-alive"
      ],
      "Sec-Ch-Ua-Mobile": [
        "?0"
      ]
    }
  },
  "duration": 0.002464627,
  "status": 502,
  "err_id": "swqm28y1w",
  "err_trace": "reverseproxy.statusError (reverseproxy.go:886)"
}
 

I just noticed it is accessible at http://n8n.digicirco.localhost:5678/ but I can’t get rid of the port …

Had to change caddy http_port to 8080 to make it work

{
http_port 8080
}
http://n8n.digicirco.localhost {
  reverse_proxy n8n {
    flush_interval 10
  }
}
version: '3.9'

services:

  caddy:
    container_name: caddy
    build: 
      context: docker/caddy
    restart: unless-stopped
    ports:
      - "80:8080"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
    links:
      - n8n

  n8n:
    container_name: n8n
    image: n8nio/n8n
    restart: always
    ports:
      - "80"
    environment:
      - N8N_PROTOCOL=http
      - N8N_PORT=80
      - NODE_ENV=production
      - GENERIC_TIMEZONE=Europe/Brussels
    volumes:
      - data/.n8n:/home/node/.n8n
1 Like