Skip to content

Mastering N8N: A Comprehensive Guide to On-Premise Self-Hosting with Cloudflare Tunnels

Part of guide: N8N TutorialsDeployment & Scaling

Watch the Video Tutorial

💡 Pro Tip: After watching the video, continue reading below for detailed step-by-step instructions, code examples, and additional tips that will help you implement this successfully.

Hey there, automation enthusiasts! Boyce here, your friendly neighborhood self-taught automation consultant. You know, I’ve been down the rabbit hole of trying to get cool tech to work, and trust me, it can feel like you’re trying to build a spaceship with a LEGO instruction manual that’s missing half its pages. That’s why I’m super stoked to walk you through setting up N8N, a seriously powerful workflow automation tool, right on your own turf. We’re talking full control, no weird cloud limitations, and all the privacy you could ask for. Let’s get this party started!

Table of Contents

Open Table of Contents

Essential Prerequisites for N8N Deployment

Alright, before we dive into the fun stuff, we need to lay some groundwork. Think of these as your mission-critical supplies. Without them, our N8N spaceship isn’t going anywhere, especially if we want it talking to the public internet.

Domain Name Acquisition

First up, you’re going to need a domain name. What’s a domain name? It’s basically your N8N’s unique address on the internet, like n8n.yourdomain.com. You can grab a brand-new one, or if you already own a domain, you can just create a subdomain. Don’t sweat the cost here; these are usually super cheap, like a fancy coffee once a year, typically ranging from $3 to $15 annually. This little piece of digital real estate is how everyone (or just you!) will find your N8N instance.

Cloudflare Account Setup and Tunnel Configuration

Next, you’ll need a Cloudflare account. And here’s the best part: their Cloudflare Tunnels product, which we’ll be using, is completely free! This is where the magic happens. Cloudflare Tunnels create a secure, encrypted connection directly from your public domain name (that one we just talked about) straight to your N8N instance, even if it’s tucked away behind your firewall. It’s like having a secret, super-fast wormhole that bypasses all the usual internet traffic jams and security checkpoints. Plus, Cloudflare can even help you register that domain name, making it a one-stop shop. Super handy, right?

The image features a man with a beard, wearing a black t-shirt, looking towards the right side of the frame. He is seated at a desk, with a pen in his right hand. The background is filled with a whiteboard or clear glass board covered in handwritten diagrams and text. Key elements include a Cloudflare logo and 'Tunnels' text, a diagram showing 'n8n.hackwell.com' connected to 'Public Internet' with arrows, and another diagram illustrating 'n8n' pointing to 'On-Prem' and 'Prereqs' with sub-points 'Domain Name' and 'Cloudflare Account'. There are also abstract network diagrams with arrows and shapes.

Registering Your Domain with Cloudflare

Ready to get started? Head over to Cloudflare’s website and sign up for a free account. Once you’re in, you’ll have the option to either connect a domain you already own or register a brand-spanking-new one directly through them. Their interface is pretty intuitive, so just follow the prompts. It’s like signing up for any other online service, but way cooler because it’s for your automation empire!

The image displays a screenshot of the Cloudflare dashboard interface for 'Domain Registration'. A man with a beard is visible in the bottom-left corner, seemingly observing the screen. The main section of the interface shows 'Register Domain' with a subtitle 'Buy a new domain at cost.' Below this, there's a search bar labeled 'Search for a domain name' with 'n8' already typed in, and a 'Search' button. A link 'Domain registration documentation' is also visible. On the right side, there's a graphical representation of a browser window with 'WWW.' highlighted, suggesting a domain name. The left sidebar shows navigation options like 'Account Home', 'Discover', 'Domain Registration', 'Manage Domains', 'Transfer Domains', and 'Register Domains' is highlighted.

Setting Up Cloudflare Tunnels

Okay, domain’s registered? Awesome! Now, let’s get that secure tunnel dug. Log into your Cloudflare dashboard and look for the ‘Zero Trust’ section. It sounds fancy, but it’s just where all the cool security stuff lives. Once there, navigate to ‘Networks’ and then ‘Tunnels’. Click on ‘Create a tunnel’ and select ‘Cloudflared’. Give your tunnel a memorable name, something like ‘n8ntunnel’ – easy to remember, right?

Cloudflare will then give you some commands to install a tiny piece of software called cloudflared on your server. This little agent is what actually creates and maintains that secure tunnel. You’ll see options for different operating systems like Windows, Mac, Linux, or even Docker. My advice? Install cloudflared on the same machine where you plan to host N8N. This keeps things simple and ensures it can easily talk to your N8N instance.

After cloudflared is installed and running (Cloudflare will show you how to verify this), you’ll go back to the Cloudflare dashboard to configure the N8N connection. Here’s what you’ll do:

  1. Set the subdomain: This is the part before your main domain, like n8n if you want n8n.yourdomain.com.
  2. Select your newly registered domain: Pick the domain you just set up.
  3. Service type: Choose HTTPS.
  4. Enter the IP address of your N8N server: This is the internal IP address of the machine where N8N will be running. For example, 192.168.1.100 or 10.0.0.50.
  5. Additional application settings: This is important! Under ‘TLS’, change the setting to ‘no TLS verify’. Why no TLS verify? Because Cloudflare is handling the public-facing SSL certificate, and your N8N instance might be using a self-signed certificate or no certificate at all internally. This setting tells Cloudflare to trust the connection to your N8N server without needing to verify its internal certificate. It’s like saying, “Hey Cloudflare, I trust my internal server, you just focus on the outside security!”

Once you’ve done all that, you’ve successfully established that secure tunnel from Cloudflare straight to your N8N server. High five!

The image displays a Cloudflare dashboard interface for adding a public hostname for an n8n tunnel. The main section is titled "Add public hostname for n8ntunnel" with a description below it. There are two main input sections: "Hostname" and "Service". Under "Hostname", there are fields for "Subdomain" (pre-filled with "n8n") and "Domain" (pre-filled with "n8niscool.cc"). A dropdown menu is visible next to the domain field. Below this, a blue information icon indicates "DNS Record for n8n.n8niscool.cc will be created". The "Service" section has fields for "Type" and "URL". The "Type" field shows a dropdown menu with options like HTTP, HTTPS, UNIX, TCP, SSH, RDP, and UNIX+TLS, with HTTP selected. The "URL" field is empty and highlighted in red, indicating it is required. A message "url is required" is visible below it. A man with a beard is visible in the top right corner of the image, partially obscuring the interface.

Installing N8N with Docker

Alright, with our domain and Cloudflare Tunnel all set up, it’s time for the main event: installing N8N! And trust me, Docker is the way to go here. It makes installing and managing N8N super easy, whether your server is sitting next to you or chilling in a data center far, far away.

Docker Installation on Ubuntu

First things first, you need to get Docker onto your server. If you’re using Ubuntu (which is a great choice for servers, by the way), here’s how you do it. You’ll need to log into your server using SSH. If you’re not sure what SSH is, it’s basically a secure way to control your server from your own computer using text commands. Think of it as a remote control for your server.

Once you’re logged in (make sure you have root or sudo access, which means you have administrator privileges), you’ll run a few commands. These commands essentially tell your Ubuntu server where to find Docker’s official software, add a special key to ensure it’s legitimate, and then install it. It’s a standard process for adding new software repositories.

sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release -y
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

Expected Feedback: You’ll see a lot of text scrolling by as packages are downloaded and installed. If everything goes well, you won’t see any big error messages. To verify Docker is installed, you can run docker --version. You should see something like Docker version 24.0.5, build 24.0.5-0ubuntu1~22.04.1 (the version number might be different, but that’s okay!).

The image displays a terminal window with command-line instructions for installing Docker on an Ubuntu system. The prompt root@srv732013:~# is visible multiple times, indicating root user access. The commands shown include sudo apt-get update, sudo install -m 0755 -d /etc/apt/keyrings, sudo curl -fSSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/key, sudo chmod a+r /etc/apt/keyrings/docker.asc, and sudo tee /etc/apt/sources.list.d/docker.list > /dev/null. Comments in the terminal indicate the purpose of the commands, such as "# Add Docker's official GPG key:" and "# Add the repository to Apt sources:". A man with a beard is visible in the top right corner of the image, partially obscuring the terminal window.

Configuring N8N Environment Variables

Now that Docker is chilling on your server, let’s tell N8N how to behave. We do this using a special file called .env. This file holds all the important settings, like your domain name and timezone. It’s like N8N’s personal instruction manual.

First, let’s create a dedicated spot for our N8N setup. I like to call it n8n-compose. Then, we’ll dive into that directory and create our .env file using a text editor like nano (it’s a super simple, command-line friendly editor).

mkdir n8n-compose
cd n8n-compose
nano .env

Once nano opens, you’ll type (or paste) the following lines. Make sure to replace the placeholder values with your actual information!

DOMAIN_NAME=n8niscool.cc # Replace with your actual domain, e.g., n8n.yourdomain.com
SUBDOMAIN=n8n # This should match the subdomain you set in Cloudflare, e.g., n8n
GENERIC_TIMEZONE=America/New_York # Find your timezone here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
SSL_EMAIL=[email protected] # Important for SSL certificate generation (especially for cloud users)

A quick note on DOMAIN_NAME and SUBDOMAIN: If you’re setting this up purely for local use (no public internet access), you can use a local domain like mycoolwebsite.local. But remember, you’d need to add that as a DNS entry on your local DNS server (like a Pi-hole) so your local devices know where to find it. For public access, stick to your real domain!

Once you’ve entered those lines, save the file in nano by pressing Ctrl+X, then Y to confirm saving, and Enter to confirm the filename. You’ll be back at your command prompt.

The image shows a terminal window displaying the content of a .env file being edited using the GNU nano text editor, version 7.2. The file contains configuration variables for an n8n instance. Key variables include DOMAIN_NAME and SUBDOMAIN, with comments explaining their purpose for determining where n8n will be reachable. DOMAIN_NAME is set to example.com and SUBDOMAIN to n8n. There's a comment indicating that this setup would result in n8n being accessible at: https://n8n.example.com. Optional settings for GENERIC_TIMEZONE (set to Europe/Berlin) and SSL_EMAIL (set to user@example.com) are also present. At the bottom of the screen, nano editor commands are listed, such as ^G Help, ^O Write Out, ^X Exit, ^R Read File, ^K Cut, ^J Justify, ^W Where Is, ^U Paste, ^T Execute, and ^C Location. A man with a beard is visible in the top right corner of the image, partially obscuring the terminal window.

Docker Compose Setup for N8N

Next up, we’re going to create a docker-compose.yml file. Think of this as the blueprint for our N8N setup. It tells Docker exactly which pieces of software (containers) to run, how they should talk to each other, and how they should use our .env file. We’ll create this file in the same n8n-compose directory.

nano docker-compose.yml

Now, paste the following content into the docker-compose.yml file. This setup includes N8N itself and a proxy called Traefik. While Traefik is often used for handling web traffic and SSL, in our case, Cloudflare Tunnels are doing most of that heavy lifting. However, it’s often simpler to just use the official N8N Docker Compose setup as-is, even if you’re using Cloudflare Tunnels, to avoid breaking things.

version: '3.8'

services:
  n8n:
    image: n8n/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - N8N_EMAIL_MODE=smtp # You might change this later if you set up email notifications
      - N8N_SMTP_HOST=your_smtp_host # Replace with your SMTP host if using email
      - N8N_SMTP_PORT=587 # Replace with your SMTP port
      - N8N_SMTP_USER=your_smtp_user # Replace with your SMTP user
      - N8N_SMTP_PASS=your_smtp_pass # Replace with your SMTP password
      - [email protected] # Replace with your sender email
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Important: Notice the N8N_HOST and WEBHOOK_URL lines? They use those SUBDOMAIN and DOMAIN_NAME variables directly from your .env file. That’s why setting up the .env file correctly was so crucial! Also, I’ve included some placeholder SMTP settings. You can leave them as is for now, but if you want N8N to send emails (like for notifications), you’ll need to fill those in with your actual email server details later.

Save this file (Ctrl+X, Y, Enter).

The image displays a terminal window on a dark background, showing command-line operations related to setting up n8n with Docker Compose. The commands include creating directories for 'n8n-compose' and 'local-files', and opening '.env' and 'docker-compose.yml' files using 'nano'. A man with a beard is visible in a circular overlay in the top right corner, looking towards the left side of the screen. The bottom of the screen shows a taskbar with various application icons and system information like time and date.

Finally, the moment of truth! With both our .env and docker-compose.yml files ready, we just need to tell Docker Compose to bring N8N to life. Run this command:

docker compose up -d

What’s happening here?

Expected Feedback: Docker Compose will download the necessary N8N image (if it hasn’t already) and then start the containers. You’ll see messages like [+] Running 2/2 or similar, indicating that the services are being created and started. To verify that everything is running smoothly, type:

docker ps

Expected Feedback: You should see output similar to this, showing your n8n container (and possibly a traefik container if you kept it in the compose file) listed with Up status, meaning they are running:

CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                    NAMES
xxxxxxxxxxxx   n8n/n8n      "tini -- /usr/local/b…"   2 minutes ago   Up 2 minutes   0.0.0.0:5678->5678/tcp   n8n-n8n-1

If you see Up next to your N8N container, you’ve nailed it!

Accessing Your N8N Instance

Congratulations, you’ve done it! Your N8N instance is now humming along, ready for action. You can access it directly through the domain name you set up earlier. For public access, it would be something like https://n8n.niscool.cc (using my example domain). If you went the local-only route, it would be https://n8n.mycoolwebsite.local.

Open your favorite web browser, type in your N8N URL, and prepare to be amazed. You’re now ready to dive into the world of automation and build some truly incredible workflows. The universe of possibilities just opened up!

The image displays a Google Chrome browser window, with the Google search page open. The address bar shows 'https://n8n.networkchuck.co' partially typed, suggesting a URL is being entered or searched. Below the search bar, there are 'Continue with these tabs' suggestions, showing previously accessed n8n-related links from 'networkchuck.co'. A man with a beard is visible in a circular overlay in the top right corner, looking towards the left side of the screen. The bottom of the screen shows a taskbar with various application icons and system information like time and date.

Required Resources and Cost-Benefit Analysis

Before you go full steam ahead, let’s talk brass tacks: what do you need, and what’s the financial picture? I’ve put together a handy list of resources and a quick comparison between doing it yourself (DIY) and opting for a commercial N8N cloud plan. It’s all about finding what fits your needs best.

Resource Checklist

CategoryItemDescriptionEstimated Cost (Annual)
HardwareServer/VPSA Linux machine (Ubuntu is my go-to recommendation)~$50 - $200 (for a decent Virtual Private Server)
StorageEnough disk space for N8N’s data (workflows, credentials, etc.)Usually included with your server/VPS
SoftwareDockerThe containerization platform we just installed (free!)Free
N8NYour awesome workflow automation tool (also free!)Free
CloudflaredThe little agent that creates our secure tunnel (yep, free!)Free
NetworkDomain NameYour N8N’s public address on the internet~$3 - $15
Cloudflare AccountFor tunnels & DNS (their free tier is perfect for this)Free
DNS Server (Local)Only if you’re doing a fully local setup (like with a Pi-hole)Free

Cost-Benefit Analysis: DIY vs. Commercial N8N Cloud

FeatureDIY Self-Hosted N8NCommercial N8N Cloud Plan
Initial Setup CostLow (just your domain and server/VPS)None (it’s subscription-based, so you just pay monthly)
Monthly/Annual Cost~$5 - $20 (for a basic VPS + domain)~$20 - $500+ (depends on the tier and features you need)
Control & CustomizationFull control over everything – your environment, your data, how you integrate things. It’s your playground!Limited to what the provider offers. You’re playing in their sandbox.
SecurityThis is on you! It depends entirely on your security practices and how well you maintain your server.Managed by the cloud provider. Generally very high, as they have dedicated security teams.
ScalabilityYou’ll need to manually upgrade your server’s resources if you need more power.Automatic scaling handled by the provider. They deal with the heavy lifting.
MaintenanceYou’re the boss! You’re responsible for updates, backups, and troubleshooting.Managed by the cloud provider. Less headache for you.
AccessibilityVia your Cloudflare Tunnel (public) or your local network (private)Publicly accessible URL, usually managed by the provider.
Best ForTech-savvy users, folks with privacy concerns, those with very specific custom needs, or anyone looking to save some serious cash.Beginners, people who want a super quick setup, those who hate maintenance, or big enterprises.

💡 Critical Best Practice Tips

Alright, you’ve got N8N running, but let’s talk about keeping it healthy and happy. These are some pro tips I’ve picked up along the way:

Key Takeaways

So, what did we learn today? A few big things, if you ask me:

Conclusion

Phew! We’ve covered a lot of ground, haven’t we? By following these steps, you’ve successfully brought your N8N instance to life, whether it’s chilling in your local lab or soaring in a cloud VPS. And the best part? You’ve securely exposed it to the internet using Cloudflare Tunnels, giving you unparalleled control over your automation workflows while keeping things super secure.

For those of us who love tinkering, crave absolute control, and want to truly understand what’s happening under the hood, self-hosting is incredibly rewarding. It might require a bit of a learning curve with networking and Docker, but the long-term benefits in terms of customization, cost savings, and sheer satisfaction are huge. Of course, if you just want to click a button and have N8N ready to go, commercial cloud plans are there for convenience. It’s all about what works for you.

Now that your N8N instance is up and running, the real fun begins. Go forth and automate! What amazing workflows will you build first? Share your ideas, I’d love to hear them!

Frequently Asked Questions (FAQ)

Q: Why do I need a domain name for self-hosting N8N?

A: A domain name acts as your N8N instance’s unique address on the internet. While you could technically access it via an IP address, a domain name (like n8n.yourdomain.com) is much easier to remember, looks more professional, and is essential for services like Cloudflare Tunnels to properly route traffic and handle SSL certificates for secure connections. Think of it as giving your N8N a proper street address instead of just GPS coordinates.

Q: What if I don’t want to expose my N8N instance to the public internet?

A: No problem at all! If you only need N8N for internal automation within your home or office network, you don’t necessarily need a public domain name or Cloudflare Tunnels. You could access it directly via its local IP address (e.g., http://192.168.1.100:5678). However, many N8N workflows benefit from webhooks or integrations that require public access, so consider your use cases. For a fully local setup, you might still use a local domain (like n8n.local) and configure your local DNS server (e.g., Pi-hole) to resolve it.

Q: My docker compose up -d command failed. What should I check?

A: Oh, the dreaded command line errors! Don’t worry, it happens to the best of us. Here are a few common culprits:

  1. Syntax Errors in docker-compose.yml or .env: Even a tiny typo (like an extra space or missing colon) can break YAML files. Double-check your docker-compose.yml and .env files for any mistakes. Use a YAML linter online if you’re unsure.
  2. Port Conflicts: Is something else already using port 5678 on your server? You can check with sudo lsof -i :5678. If so, you might need to change the ports mapping in your docker-compose.yml (e.g., "8080:5678").
  3. Docker Not Running: Make sure the Docker daemon itself is running. You can check its status with sudo systemctl status docker and start it with sudo systemctl start docker if it’s not active.
  4. Insufficient Resources: Does your server have enough RAM and CPU? N8N can be a bit resource-hungry, especially if you plan complex workflows. Check your server’s resource usage.
  5. Check Logs: The most important step! Run docker compose logs (without -d) to see the output from your N8N container. This will often tell you exactly what went wrong.

Q: Why did we set TLS to no TLS verify in Cloudflare? Is that secure?

A: That’s a great question, and it’s smart to be cautious about security settings! When we set TLS to no TLS verify in Cloudflare, we’re telling Cloudflare’s cloudflared agent not to validate the SSL certificate presented by your N8N server internally. This is generally secure in this setup because:

  1. Cloudflare handles public SSL: Cloudflare itself is providing the valid, trusted SSL certificate for https://n8n.yourdomain.com to your users. So, the connection from the user’s browser to Cloudflare is fully encrypted and verified.
  2. Internal network trust: The connection from Cloudflare’s edge (via the cloudflared agent) to your N8N server is over your internal network or a highly controlled path. In many self-hosting scenarios, your internal N8N might use a self-signed certificate (which browsers don’t trust publicly) or no certificate at all. no TLS verify simply tells cloudflared to proceed with the connection despite this, as the primary security is handled by Cloudflare at the public-facing end. It’s a common and accepted practice for this specific tunnel setup.

Q: Can I use a different proxy instead of Cloudflare Tunnels, like Nginx Proxy Manager or Traefik directly?

A: Absolutely! While Cloudflare Tunnels are fantastic for their simplicity and free tier, you can definitely use other reverse proxies. Tools like Nginx Proxy Manager or setting up Traefik directly (without Cloudflare Tunnels) are popular choices. These would typically require you to open ports on your firewall (like 80 and 443) and configure DNS A records to point directly to your server’s public IP address. You’d also need to handle SSL certificate generation (often with Let’s Encrypt) yourself. Cloudflare Tunnels simplify this by not requiring open ports and handling the SSL for you, but other proxies offer more granular control over routing and advanced features if you need them.


Related Tutorials

Install n8n Locally for Free: Your Guide to Building AI Agents with Docker

Unlock the full potential of n8n for free by installing it locally using Docker. This guide cuts through complex setups, offering a streamlined process that saves you hours of dependency headaches and

HANDBOOK: Deployment And Scaling • DIFFICULTY: ADVANCED

Seamless n8n Updates on Docker Desktop: A Data-Safe Guide

Learn how to update your n8n instance on Docker Desktop without losing any data. This comprehensive guide covers stopping containers, managing images, and reconfiguring your new n8n environment for a

HANDBOOK: Deployment And Scaling • DIFFICULTY: ADVANCED

Mastering n8n Updates on Hostinger VPS: A Step-by-Step Guide

Unlock seamless n8n updates and self-hosting on Hostinger VPS with this comprehensive guide, ensuring your automation workflows are always running on the latest, most reliable version.

HANDBOOK: Deployment And Scaling • DIFFICULTY: ADVANCED

10 Insane AI Agent Use Cases in n8n to Reclaim Your Time

Discover 10 powerful AI agent use cases in n8n that can automate up to 80% of your daily tasks, freeing up countless hours and boosting your productivity significantly.

HANDBOOK: Advanced Features • DIFFICULTY: ADVANCED

Unleashing Grok 4: A Deep Dive into XAI's Latest AI Model and Its Integration with n8n

Discover Grok 4, XAI's groundbreaking AI model, and learn how to integrate its advanced capabilities with n8n for smarter, more efficient AI automations. This guide covers Grok 4's benchmarks, key fea

HANDBOOK: Advanced Features • DIFFICULTY: ADVANCED

Automate Viral AI Videos for FREE: n8n + Veo 3 Integration Guide

Discover how to automate viral AI video creation using Google's Veo 3 and n8n, completely for free. This guide provides a step-by-step process to generate, store, and manage AI-generated video content

HANDBOOK: Advanced Features • DIFFICULTY: ADVANCED
Share this post on: