Skip to content

Instantly share code, notes, and snippets.

@rskupnik
Created February 24, 2025 12:45
Show Gist options
  • Select an option

  • Save rskupnik/4f0b388b5cc60e50c4f489cd565e4723 to your computer and use it in GitHub Desktop.

Select an option

Save rskupnik/4f0b388b5cc60e50c4f489cd565e4723 to your computer and use it in GitHub Desktop.
How to self-host n8n but expose the path for OAuth2 authentication
# Add this part to your cloudflared config
ingress:
- hostname: n8n.yourcustomdomain.com
service: http://traefik:80
# Remember that this needs to be a part of 'your-network' along with your traefik reverse proxy container
services:
n8n:
image: docker.n8n.io/n8nio/n8n
container_name: n8n
restart: unless-stopped
environment:
N8N_HOST: n8n.home
N8N_PORT: 5678
N8N_PROTOCOL: http
N8N_SECURE_COOKIE: false
NODE_ENV: production
WEBHOOK_URL: https://n8n.yourcustomdomain.com/
volumes:
- n8n_data:/home/node/.n8n
networks:
- your-network
volumes:
n8n_data:
networks:
your-network:
name: your-network
# Copy all the files (excluding MD, png) to /home/pi/n8n
deploy:
rsync -avh --inplace --no-perms --exclude '*.MD' --exclude '*.png' * {{rpi_user}}@{{rpi_hostname}}:/home/pi/n8n/
# Start the service
start:
ssh {{rpi_user}}@{{rpi_hostname}} 'cd n8n && docker compose up -d --build'
# Stop the service
stop:
ssh {{rpi_user}}@{{rpi_hostname}} 'cd n8n && docker compose down'
# Display Docker logs for service
log:
ssh {{rpi_user}}@{{rpi_hostname}} 'docker logs -f n8n'
http:
routers:
n8n:
rule: "Host(`n8n.home`)"
entrypoints:
- "web"
service: "n8n"
n8n_yourcustomdomain:
rule: "Host(`n8n.yourcustomdomain.com`) && PathPrefix(`/rest/oauth2-credential`)"
entrypoints:
- "web"
service: "n8n"
n8n_yourcustomdomain_deny:
rule: "Host(`n8n.yourcustomdomain.com`)"
entrypoints:
- "web"
service: "deny-all"
services:
n8n:
loadBalancer:
servers:
- url: "http://n8n:5678"
deny-all:
loadBalancer:
servers:
- url: "http://0.0.0.0" # A dummy service that always fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment