Concept #99Mediumextended-ai-concepts

How to connect local n8n with outside network?

#gen-ai#mlops

Answer

How to Connect Local n8n with Outside Network

By default, n8n runs on

text
localhost
and is only accessible on your machine. To access it from outside your local network (webhooks, remote access, external integrations), you need to expose it.

Why You Need External Access

n8n workflows often use webhooks — external services (Slack, GitHub, payment processors) send HTTP requests to your n8n instance. This requires a publicly accessible URL.

Option 1: ngrok (Easiest — Development)

bash
# Install ngrok
brew install ngrok  # Mac
# or download from ngrok.com

# Authenticate
ngrok config add-authtoken YOUR_TOKEN

# Expose n8n (running on port 5678)
ngrok http 5678

ngrok gives you a public URL like

text
https://abc123.ngrok.io
that tunnels to your local n8n.

bash
# Set n8n webhook URL to ngrok URL
export WEBHOOK_URL=https://abc123.ngrok.io
n8n start

Limitation: Free ngrok URLs change every restart. Use ngrok's paid plan for a fixed URL.

Option 2: Cloudflare Tunnel (Free + Stable)

bash
# Install cloudflared
brew install cloudflare/cloudflare/cloudflared

# Login to Cloudflare
cloudflared tunnel login

# Create a tunnel
cloudflared tunnel create n8n-tunnel

# Create config
cat > ~/.cloudflared/config.yml << EOF
tunnel: n8n-tunnel
credentials-file: /Users/you/.cloudflared/n8n-tunnel.json
ingress:
  - hostname: n8n.yourdomain.com
    service: http://localhost:5678
  - service: http_status:404
EOF

# Add DNS record (automatic)
cloudflared tunnel route dns n8n-tunnel n8n.yourdomain.com

# Run the tunnel
cloudflared tunnel run n8n-tunnel

Now

text
https://n8n.yourdomain.com
permanently points to your local n8n.

Option 3: VPS / Cloud Deployment

For production, run n8n on a server:

bash
# Docker on VPS (DigitalOcean, Linode, Hetzner)
docker run -d   --name n8n   -p 5678:5678   -e N8N_HOST=your-domain.com   -e WEBHOOK_URL=https://your-domain.com   -e N8N_PROTOCOL=https   -v n8n_data:/home/node/.n8n   n8nio/n8n

Add nginx + Let's Encrypt for HTTPS.

Option 4: n8n Cloud

Simplest — use n8n's hosted service at cloud.n8n.io. No infrastructure management needed.

Comparison

MethodCostSetupStabilityBest For
ngrok freeFreeEasyUnstable URLQuick testing
ngrok paid$8+/moEasyStable URLDevelopment
Cloudflare TunnelFreeMediumStableDevelopment + staging
VPS (self-hosted)$5-20/moHardProduction-gradeProduction
n8n Cloud$20+/moNoneProduction-gradeEasiest production

Set Webhook URL in n8n

bash
# Environment variable approach
N8N_HOST=your-domain.com N8N_PORT=5678 N8N_PROTOCOL=https WEBHOOK_URL=https://your-domain.com n8n start

This is critical — n8n uses

text
WEBHOOK_URL
to tell external services where to send webhooks. Without it set correctly, webhook nodes won't work from external services.