n8n self hosting - qwikbits tutorial

How to Set Up Self-Hosted n8n on Google Cloud Free Tier (2025 Guide)

Self Hosted n8n in Google Cloud Computing

n8n is a powerful, open-source workflow automation tool that allows you to connect various services and automate tasks with ease. In this guide, we’ll walk you through the process of setting up a self-hosted n8n instance on Google Cloud Platform’s (GCP) Free Tier, using Docker Compose for simplicity, and securing it with a Cloudflare Tunnel for SSL and domain redirection. This setup ensures you can run n8n securely without incurring costs, leveraging GCP’s always-free e2-micro instance and Cloudflare’s free tier.

Why Self-Host n8n on Google Cloud?

Self-hosting n8n gives you full control over your workflows and data, which is crucial for privacy and customization. Google Cloud’s Free Tier offers an e2-micro instance that’s perfect for lightweight applications like n8n, and Cloudflare Tunnels provide a secure way to expose your instance to the internet without opening ports on your server. This combination is cost-effective, secure, and scalable.

Prerequisites

  • A Google Cloud Platform account (sign up for free)
  • A domain managed by Cloudflare (free account)
  • Basic familiarity with SSH and command-line interfaces
  • A computer with SSH client (e.g., Terminal on macOS/Linux, PuTTY on Windows)

Step-by-Step Instructions

Follow these steps to deploy n8n on GCP Free Tier and set up a Cloudflare Tunnel for secure access.

Step 1: Set Up Google Cloud VM Instance

  1. Create a GCP Project
    • Go to the Google Cloud Console.
    • Click the project dropdown at the top, select New Project, and name it (e.g., n8n-project).
    • Ensure billing is enabled (required for GCP, but we’ll stay within the free tier).
  2. Create an e2-micro VM Instance
    • Navigate to Compute Engine > VM Instances.
    • Click Create Instance and configure:
      • Name: n8n-instance
      • Region: us-central1 (or any free-tier eligible region)
      • Zone: us-central1-a
      • Machine type: e2-micro (free tier eligible)
      • Boot disk: Ubuntu 22.04 LTS, 10 GB standard persistent disk
      • Firewall: Check Allow HTTP traffic and Allow HTTPS traffic
    • Click Create to launch the VM.
  3. Reserve a Static External IP
    • Go to VPC Network > IP addresses.
    • Click Reserve static address, name it n8n-static-ip, and select your region.
    • Assign this IP to your VM under VM Instances > Edit > Network interfaces.

Step 2: Install Docker and Docker Compose

  1. SSH into Your VM
    • In the GCP Console, go to VM Instances, click SSH next to n8n-instance.
  2. Update the System and Install Docker
    sudo apt update && sudo apt upgrade -y
    sudo apt install -y docker.io
    sudo systemctl enable docker
    sudo usermod -aG docker $USER
    newgrp docker
    
  3. Install Docker Compose
    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    docker-compose --version
    

Step 3: Configure n8n with Docker Compose

  1. Create a Docker Compose File
    • Create a directory and file:
      mkdir ~/n8n
      nano ~/n8n/docker-compose.yml
      
    • Paste the following configuration, replacing <your-external-ip> with your VM’s static IP:
      version: "3"
      services:
        n8n:
          image: n8nio/n8n:latest
          restart: always
          ports:
            - "5678:5678"
          environment:
            - N8N_BASIC_AUTH_ACTIVE=true
            - N8N_BASIC_AUTH_USER=admin
            - N8N_BASIC_AUTH_PASSWORD=admin@123
            - N8N_HOST=<your-external-ip>
            - N8N_PORT=5678
            - N8N_PROTOCOL=http
            - N8N_SECURE_COOKIE=false
          volumes:
            - n8n_data:/home/node/.n8n
      volumes:
        n8n_data:
      
    • Save and exit (Ctrl+O, Enter, Ctrl+X).
  2. Start n8n
    cd ~/n8n
    docker-compose up -d
    
  3. Verify n8n is Running
    • Open a browser and navigate to http://<your-external-ip>:5678.
    • Log in with username admin and password admin@123.

Note: Change the default password immediately after logging in for security.

Step 4: Set Up Cloudflare Tunnel for SSL and Domain Redirect

  1. Add Your Domain to Cloudflare
    • Sign up for a free Cloudflare account at cloudflare.com.
    • Go to Add Site, enter your domain (e.g., yourdomain.com), and follow the prompts.
    • Update your domain’s nameservers to Cloudflare’s as instructed (this may take up to 24 hours to propagate).
  2. Create a Cloudflare Tunnel
    • In the Cloudflare dashboard, go to Zero Trust > Networks > Tunnels.
    • Click Create a tunnel, name it (e.g., n8n-tunnel), and select Cloudflared.
    • Follow the provided command to install cloudflared on your VM:
      curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared-linux-amd64.deb
      sudo dpkg -i cloudflared-linux-amd64.deb
      
    • Authenticate the tunnel:
      cloudflared tunnel login
      
      • Copy the provided URL, open it in a browser, and select your domain to authorize.
    • Create the tunnel:
      cloudflared tunnel create n8n-tunnel
      
      • Note the generated Tunnel ID.
  3. Configure the Tunnel
    • Create a configuration file:
      mkdir ~/.cloudflared
      nano ~/.cloudflared/config.yml
      
    • Paste, replacing <tunnel-id> with your Tunnel ID and <your-subdomain> with your desired subdomain (e.g., n8n.yourdomain.com):
      tunnel: <tunnel-id>
      credentials-file: /home/$USER/.cloudflared/<tunnel-id>.json
      ingress:
        - hostname: <your-subdomain>
          service: http://localhost:5678
        - service: http_status:404
      
    • Save and exit.
    • Create a DNS record:
      cloudflared tunnel route dns n8n-tunnel <your-subdomain>
      
    • Run the tunnel:
      cloudflared tunnel run n8n-tunnel
      
  4. Verify Access
    • Visit https://<your-subdomain> in a browser.
    • Log in to n8n using the same credentials.

Step 5: Secure and Optimize Your Setup

  1. Update n8n Environment Variables
    • Edit docker-compose.yml to use your domain and HTTPS:
      N8N_HOST=<your-subdomain>
      N8N_PROTOCOL=https
      N8N_SECURE_COOKIE=true
      
    • Restart n8n:
      docker-compose down
      docker-compose up -d
      
  2. Enable Cloudflare Security Features
    • In Cloudflare, go to SSL/TLS > Overview and set to Full.
    • Enable Always Use HTTPS under SSL/TLS > Edge Certificates.
    • Optionally, configure Web Application Firewall rules to restrict access.
  3. Monitor GCP Usage
    • Check Billing > Reports in GCP to ensure you’re within free tier limits (e2-micro, 30 GB disk, 1 GB egress/month).

Troubleshooting Tips

  • n8n not accessible: Check Docker logs (docker logs <container-id>) and ensure port 5678 is open.
  • Cloudflare Tunnel errors: Verify config.yml and DNS records in Cloudflare.
  • DNS propagation delays: Wait up to 24 hours or use a DNS checker like dnschecker.org.

Conclusion

By following this guide, you’ve set up a secure, self-hosted n8n instance on Google Cloud’s Free Tier, accessible via a custom domain with SSL through Cloudflare Tunnels. This setup is ideal for small-scale automation projects and can be scaled up if needed. Explore n8n’s nodes to automate your workflows and enhance productivity!

For more details, check the n8n Documentation or n8n Community Forum.

Have questions or run into issues? Leave a comment below or join the n8n community for support!

Leave a Reply

Your email address will not be published. Required fields are marked *