Option to Assign Custom Webhook URL (for Cloudflare Tunnel Deployments)

When deploying n8n on localhost and using a Cloudflare tunnel, the webhook node still gets assigned the local address instead of the tunnel URL. This causes issues when external services try to access the webhook.

I think n8n should have an option to manually assign a webhook address, so we can directly set the tunnel URL as the webhook.

Hey @foginevury hope all is well. Welcome to the community.
Have you set the WEBHOOK_URL env variable? Have you restarted the instance after that?

No, I haven’t done that yet. Could you please guide me on how to set the WEBHOOK_URL environment variable and restart the instance properly?

You would usually set this under environments in your docker compose or you pass this environment variable with docker run command.

See the following guides:

As to rebooting - that solely depends on how you are running your instance. Tell us more about that.

I’m not using Docker. I installed n8n with npm install -g n8n.
In this case, how can I set the tunnel link as the webhook URL?

You can either prepend the variable before starting n8n

WEBHOOK_URL=https://example.com/ n8n

or you can export your variable and then start n8n

export WEBHOOK_URL=https://example.com/
n8n

I think it should also be possible to store env vars to a file .env in the place where you run n8n from

.env

WEBHOOK_URL=https://example.com/

and then run n8n

n8n

Yes, it worked! :tada:

Here’s the permanent solution for setting the webhook URL so n8n always uses the tunnel link instead of localhost:

Windows:

  • Go to System Properties > Environment Variables
  • Add a new system variable:
    • Name: WEBHOOK_URL
    • Value: https://your-tunnel-link.domain/
  • Save and restart your terminal/PC

Linux / Mac:

  • Open your shell config file (~/.bashrc, ~/.zshrc, etc.)
  • Add this line:
    export WEBHOOK_URL=https://your-tunnel-link.domain

If my answer helped you to solve your problem, kindly mark my answer as Solution.
Thanks.

Cheers.