Hopefully, it will be useful to others
I run n8n with Postgres on my laptop and OAuth2 and more requested a static domain to redirect.
As my laptop is on the road; I’m fine with unstable executions time; I had to find a way to make stable the URL to access n8n even if I can’t configure (open port) the router or my public IP change; this is the role of CloudFlared (aka a Road Warrior reverse proxy)
docker-compose.yml
version: '3'
volumes:
n8n_db:
n8n_data:
services:
postgres:
image: postgres:11
restart: unless-stopped
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_NON_ROOT_USER
- POSTGRES_NON_ROOT_PASSWORD
volumes:
- n8n_db:/var/lib/postgresql/data
- ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
healthcheck:
test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 5s
timeout: 5s
retries: 10
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
- WEBHOOK_URL=https://URL.DOMAIN.TLD
links:
- postgres
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
cloudflared:
image: cloudflare/cloudflared
command: tunnel --no-autoupdate run
env_file: .env_cloudflare
restart: unless-stopped
depends_on:
- n8n
while in .env_cloudflare I simply cut and past the token of the tunnel like this
-
in this example .env_cloudflare would contain:
TUNNEL_TOKEN=eyJhIjoiY2E1M2MyZmFiOWZkMGI5MmQ4NTg1MGU3NTEwNWQ5ZjQiLCJ0IjoiNTcxMGQ3MmMtNTkzNi00NjRhLWE4NmYtOTViMWIyMDY0YzFkIiwicyI6Ik4yTXpaREF6TkdFdFlUUXpaaTAwWW1FeExXRm1ZV1V0T0RRMU1tUm1PV1JrWVRJeiJ9
WEBHOOK
Yes the WEBHOOK_URL and the https:// are important
CLOUDFLARE SIDE
Yes the Service URL need to reflect the NAME of the service and the PORT you want to expose