Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 58

External Access and Webhook Tunnel Configuration

Recommended resources

Introduction

In our last lesson, we established a robust foundation for your self-hosted n8n instance by deploying it with Docker Compose and configuring PostgreSQL as a persistent database. While this setup is production-ready in terms of data integrity, it remains isolated and accessible only at localhost. To integrate with CI/CD tools like GitHub or Jenkins, n8n must be reachable from the public internet to receive webhook notifications.

This lesson directly addresses that challenge. Our objective is to configure n8n's networking for external access. We will explore why a public URL is necessary, how to correctly inform n8n of its public address using environment variables, and implement a secure method for exposing your local instance to the web using a "webhook tunnel." This is the crucial step that transforms n8n from a local tool into a connected hub for your automation pipelines.


The Problem: An Isolated Instance

When a service like GitHub needs to notify n8n of a git push event, it does so by sending an HTTP POST request to a pre-registered webhook URL. If your n8n instance only knows its address as localhost:5678, it will try to register that URL with the external service. However, localhost is a private address that resolves only on your own machine. From GitHub's perspective, this address is meaningless, and the connection will fail.

Furthermore, most services require webhooks to use a secure HTTPS connection, but our current setup only serves HTTP. The error message in the image below, taken from a Telegram trigger node, perfectly illustrates this issue: the webhook URL is on localhost, and the service rejects it because an HTTPS URL is required.

An error in the n8n interface showing that an external service has rejected a webhook URL because it is not served over HTTPS.

To solve this, n8n needs a public, secure (HTTPS) address, and it needs to be aware of this address to generate correct webhook URLs.


Configuring n8n's Public Address

n8n generates webhook URLs based on its environment configuration. By default, it uses variables like N8N_HOST and N8N_PORT, which resolve to localhost:5678 in our current Docker setup. When n8n is running behind a reverse proxy or a tunnel—which is always the case for a publicly accessible instance—we must explicitly tell it its final, public-facing URL.

This is done by setting the WEBHOOK_URL environment variable. This variable overrides the default URL generation and becomes the base for all webhook URLs that n8n creates.

The official n8n documentation provides a concise explanation of this and related settings.

Configure webhook URLs with reverse proxy

This document explains the core environment variables needed to make n8n work correctly behind a reverse proxy or tunnel.

Please read the entire page. Pay close attention to the role of the WEBHOOK_URL variable and the explanation for why it's necessary. The details on X-Forwarded-* headers are also important context for how proxies communicate with backend applications like n8n.

As the documentation states, you must set WEBHOOK_URL to your public domain (e.g., https://n8n.yourdomain.com). This variable can be defined in your .env file or directly within the environment section of the n8n service in your docker-compose.yml.

An example showing the `WEBHOOK_URL` environment variable set in both a `compose.yaml` and a `.env` file, demonstrating the two primary methods for configuration.

Hands-On: Exposing n8n with a Cloudflare Tunnel

Now, let's create a public URL and configure our n8n stack to use it. While a traditional reverse proxy like Nginx on a cloud server is a common production pattern (which we will cover later), a tunneling service is an exceptionally convenient and secure way to expose a service running on a local machine or in a restricted network. We will use Cloudflare Tunnel for this.

The video "How to Set Up a Cloudflare Tunnel for Local n8n" provides a clear, step-by-step walkthrough of the entire process. We will follow its guidance to get our instance online.

Prerequisites:

  • A Cloudflare account (free tier is sufficient).
  • A domain name managed through Cloudflare. You can purchase one directly from Cloudflare if needed.

How to Set Up a Cloudflare Tunnel for Local n8n (2025)

This video guides you through the process of creating a Cloudflare Tunnel and connecting it to your local n8n Docker instance. We will break it down into segments.

1. Understanding and Creating the Tunnel First, watch the section that explains the concept of a tunnel and guides you through creating one in the Cloudflare Zero Trust dashboard. This will establish the secure link between Cloudflare's network and your local machine. Watch from the start of tunnel creation. He also provides a helpful diagram and explanation of how the tunnel bypasses firewalls. Watch this conceptual overview from the diagram explanation. 2. Configuring the Public Hostname Next, you'll configure the public-facing URL. This step points your chosen subdomain (e.g., n8n.yourdomain.com) to your local n8n service running on localhost:5678. Watch this configuration process from adding the public hostname. After this step, you should be able to access your n8n instance via the new public, HTTPS-enabled URL. 3. Updating the n8n Docker Configuration This is the most critical part. Even though n8n is accessible at the public URL, it doesn't know it yet. You must update your Docker configuration to set the WEBHOOK_URL and restart the container. Watch the process of editing the docker-compose.yml file from editing the environment variables. Follow along as he restarts the Docker stack to apply the changes from restarting the container. Your experience with Docker Compose will make this step straightforward. 4. Verification Finally, verify that the change was successful. Once the container restarts, access n8n via its public URL, create a new workflow with a webhook-based trigger (like the Webhook or Telegram Trigger node), and confirm that the generated URL now uses your public domain. Watch the final verification step from the final check.

To reinforce the crucial "edit, restart, verify" cycle, the following short video also demonstrates this exact process: editing the docker-compose.yml file, running docker compose down followed by docker compose up -d, and then checking the n8n UI to confirm the webhook URL has been updated.

Master n8n: Set Up Environment Variables Easily!

This video provides another concise demonstration of modifying the WEBHOOK_URL and restarting the Docker stack.

Watch the section showing how to edit the Docker Compose file to change the WEBHOOK_URL. Then, observe the restart and verification process. This familiar down and up cycle is standard practice for applying configuration changes in Docker Compose.

By completing these steps, you have successfully configured n8n with a public "webhook tunnel URL," making it fully capable of participating in external, event-driven workflows.


Conclusion

In this lesson, you have bridged the gap between your isolated, self-hosted n8n instance and the public internet. You now have a secure, publicly accessible endpoint for your automation workflows, a cornerstone for building the CI/CD pipelines that are your ultimate goal.

Key Takeaways:

  • External services require a public, HTTPS-enabled URL to send webhook data to n8n.
  • The WEBHOOK_URL environment variable is the essential configuration for telling n8n its public address.
  • Cloudflare Tunnel provides a secure and convenient method for exposing a local service without needing a public IP or complex firewall rules.
  • The configuration process involves creating the tunnel, updating the WEBHOOK_URL in your Docker environment, and restarting the n8n container to apply the changes.

Your n8n instance is now fully connected. In our next lesson, we will explore an alternative and more traditional approach to production deployments: configuring an Nginx reverse proxy on a virtual private server to manage traffic and secure your instance with SSL certificates. This will give you another powerful option for your deployment toolkit.