How to Fix "Webhook URL shows Localhost" Error in n8n (VPS Solution)

How to Fix "Webhook URL shows Localhost" Error in n8n (VPS Solution)

🐞 You've deployed n8n on a VPS, created a webhook workflow, but the URL shows http://localhost:5678/webhook/... instead of your public domain. When you try to call it, you get a 404 or connection refused error. This is one of the most common n8n errors after self‑hosting.

In this guide, I'll show you exactly how to fix it in 5 minutes – no Docker wizardry required.

Why Does This Error Happen?

When you run n8n locally during development, it automatically uses localhost. After moving to a VPS, n8n doesn't magically know your domain. It keeps using the old localhost address for webhook URLs unless you tell it otherwise.

💡
The webhook URL is generated based on N8N_HOST and N8N_PROTOCOL. If these aren't set, n8n falls back to localhost.
n8n webhook showing localhost error
Fig 1. The error – localhost appears instead of your domain.

Fix #1: Set Environment Variables (Most Important)

If you're running n8n with Docker, add these environment variables to your docker-compose.yml or run command:

docker-compose.yml
version: '3'
services:
  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - N8N_HOST=your-domain.com
      - N8N_PROTOCOL=https
      - N8N_PORT=5678
    ports:
      - "5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  n8n_data:

If you're using systemd (without Docker), edit the service file or add to .env:

.env
N8N_HOST=your-domain.com
N8N_PROTOCOL=https
N8N_PORT=5678
WEBHOOK_URL=https://your-domain.com/

After changing, restart n8n: docker restart n8n or sudo systemctl restart n8n.

Fix #2: Configure SSL (If You're Using HTTPS)

If your domain has HTTPS (which it should), you also need to set N8N_PROTOCOL=https. Without this, webhook URLs will still use http:// and your browser may block them.

🔒
Use Let's Encrypt with Nginx to get a free SSL certificate. Then set N8N_PROTOCOL=https and N8N_HOST=your-domain.com.
Nginx configuration for n8n
Fig 2. Nginx config – make sure proxy_set_header Host is set correctly.

Fix #3: Activate Your Workflow

Even after fixing the URL, n8n won't listen for webhooks unless the workflow is Active (the toggle switch at the top right). A common mistake: you've set everything up but forgot to turn the workflow on.

⚠️
Always double‑check the workflow status. Inactive workflows return 404 even if the URL is correct.

Testing Your Webhook

Use a free tool like webhook.site or Postman to send a test POST request to your new webhook URL. You should see the execution in n8n.

cURL test command
curl -X POST https://your-domain.com/webhook/your-path \
  -H "Content-Type: application/json" \
  -d '{"test": "Hello from TriggerWorkflow"}'
🎉
Fixed! Your webhook now uses your public domain. It will work with any external service (Shopify, Typeform, Google Forms, etc.).

Frequently Asked Questions

Do I need to restart n8n after changing environment variables?
Yes, absolutely. Environment variables are read at startup. Run docker restart n8n or restart your systemd service.
My webhook still shows localhost after restart – why?
Check if you have a misconfigured WEBHOOK_URL variable. Remove it and rely on N8N_HOST + N8N_PROTOCOL instead. Also ensure your workflow is active.
Does this affect existing workflows?
No, existing workflows will automatically use the new URL for their webhook nodes. You don't need to recreate them.

What's Coming Next

TriggerWorkflow Team
We've fixed this error dozens of times. Follow these steps and you'll be up in minutes.

Post a Comment

Previous Post Next Post