Self-Hosted n8n docker not reachable through domain name, but works with localhost

I’m a newbie on n8n. I’m running n8n in a docker and only have one Telegram trigger node on my canvas. I’ve created a bot in Telegram. The http://localhost:5678 works but not http://n8n.<domain name>:5678 said server unreachable. The dns was able to resolve n8n.<domain name> to my m3 mbp public IP. I disabled my firewall. What am I doing wrong?

The log output says

n8n | Tunnel URL: https://xxxxxxxxxxxx.hooks.n8n.cloud/
n8n |
n8n | IMPORTANT! Do not share with anybody as it would give people access to your n8n instance!
n8n | Version: 1.69.2
n8n |
n8n | Editor is now accessible via:
n8n | http://localhost:5678/

Here is my docker compose setup with non-relevant stuff removed.

volumes:
n8n_storage:

networks:
demo:

x-n8n: &service-n8n
image: n8nio/n8n:latest
networks: [‘demo’]
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_DIAGNOSTICS_ENABLED=false
- N8N_PERSONALIZATION_ENABLED=false
- N8N_ENCRYPTION_KEY
- N8N_USER_MANAGEMENT_JWT_SECRET
links:
- postgres

services:
n8n:
<<: *service-n8n
container_name: n8n
restart: unless-stopped
ports:
- 5678:5678
environment:
- HOST=n8n.<domain name>
- N8N_PROTOCOL=http
- N8N_SECURE_COOKIE=false
volumes:
- n8n_storage:/home/node/.n8n
- ./n8n/backup:/backup
- ./shared:/data/shared
depends_on:
postgres:
condition: service_healthy
n8n-import:
condition: service_completed_successfully
command: “start --tunnel”

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

n8n version: 1.69.2
Database: default
n8n EXECUTION_PROCESS: default
Running n8n via: Docker
OS: Mac Sequoia 15.1.1

Hey you need to setup some sort of reverse web proxy on a serverto use nginx or caddy or your preferred options …assuming you are using a server

as it looks like you’re using localhost then suggest reading up on ngrok…

Also research the telegram requirements…as it may need an internet server

Theres a quick start docker stack for servers that will help you get up and running…or just use the n8n cloud if server management is not your thing…

Yes I am using a server in a docker container with image n8n. I will look into nginx.

I finally got to NGINX from a <subdomain>.<domainname>:5100 with the following steps, but I’m still getting an error “502 Bad Gateway\nnginx/1.27.3”, albeit a better error. What could be wrong? Appreciate any insight you can shed on this. I can run n8n on my M3 using “http://127.0.0.1:5678” and “http://localhost:5678”, but get this 502 error when I use “http://<subdomain>.<domainname>:5100”.

Setup

Setup

  1. I did a port forwarding on my internet router that routes <subdomain>.<domainname>:5100 to my M3 MacBook’s port of 5678 (http://localhost:5678), which my n8n is hosted under a docker container.
  2. I setup nginx in another docker container as a reverse proxy that routes incoming call to my docker n8n service.
  3. I added 127.0.0.1 <subdomain>.<domainname> to my M3 hosts file. Before this step, I would get “Safari can’t connect to server” in my private network.

nginx.conf

server {
    listen 80;

    server_name <subdomain>.<domainname>;

    location / {
        proxy_pass http://localhost:5678;
        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-Proto $scheme;
    }
}

docker-compose.xml

  n8n:
    <<: *service-n8n
    container_name: n8n
    restart: unless-stopped
    ports:
      - 5678:5678
    environment:
      - HOST=<subdomain>.<domainname>
      - N8N_PROTOCOL=http
      - N8N_SECURE_COOKIE=false
    volumes:
      - n8n_storage:/home/node/.n8n
      - ./n8n/backup:/backup
      - ./shared:/data/shared
    depends_on:
      postgres:
        condition: service_healthy
      n8n-import:
        condition: service_completed_successfully
    command: "start --tunnel"

  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "5100:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    command: ["nginx", "-g", "daemon off;"]
1 Like