Tired of self-hosting n8n and having to keep your laptop on 24/7? This tutorial shows you how to host n8n on a Google Cloud server for absolutely free, forever, so you can enjoy all the services of n8n uninterrupted. We will use the Google Cloud free tier to get an always-free server.

    The server we will set up is an E2 micro instance, which is generally free. It provides 2 GB of RAM. This setup may lag a little bit, but it is perfectly suited for testing out n8n and getting started with automation.Understanding the Google Cloud Free Tier

    Before starting, it’s important to understand the Google Cloud Free Tier:

    • E2 Micro VM Instance: You get one E2 micro VM instance per month, absolutely for free.
    • Regions: The free E2 micro VM is available in three regions: Oregon, Iowa, and South Carolina.
    • Storage: You receive 30 GB of memory storage for Compute Engine. Compute Engine is essentially the server that we will use.

    Step-by-Step Tutorial: Setting up n8n on Google Cloud

    1. Google Cloud Account Setup and Billing Verification

      1. Go to the Google Cloud free page: cloud.google.com/free.

      2. Set up your Google Cloud account, including setting up billing. You will need to add a name, address, and payment method. This is required for verification to prove you are a real user and not a bot. You will not be charged.

      3. In the GCP console, create a new project. The speaker named their project "n8nn".

      4. Enable the Compute Engine API to get permission to set up the engine via the web UI.

    2. Creating the E2 Micro VM Instance

      1. Go to Compute Engine and select Create Instance.

      2. Choose the machine type E2 for low-cost computing.

      3. Select the E2 micro machine configuration, as it is included in the free tier.

      4. Under the settings, change the default storage from 10 GB to 30 GB to maximize the free storage available.

      5. Set the operating system to Linux and make sure to disable snapshots, as backups cost money.

      6. Enable HTTP and HTTPS traffic.

      7. Disable all observability (logging and monitoring) because it is an additional cost.

      8. Click Create.

    3. Connecting via SSH and Installing Docker

      1. Once the instance is created, connect to the server by pressing the SSH button. SSH allows you to log in to the server.

      2. After connecting, you will see an empty directory. Do a simple library update:

        sudo apt update
      3. Check if Docker is installed:

        docker
      4. Install the necessary libraries, the most important being Docker. Docker allows you to run the n8n instance easily without installing everything individually:

        sudo apt update && sudo apt upgrade -y
        
        sudo apt install -y ca-certificates curl gnupg
        
        sudo install -m 0755 -d /etc/apt/keyrings
        
        curl -fsSL https://download.docker.com/linux/debian/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/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
        
        sudo apt update
        
        sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
        
        sudo systemctl enable --now docker
        
        sudo docker run -it --rm --name n8n -p 5678:5678 docker.n8n.io/n8nio/n8n
    4. Setting up Network and Static IP

      1. To access n8n from the web, you need to allow access. Go to the network settings for the E2 instance.

      2. Create a VPC firewall rule to allow access from any IP address on the entire internet. The speaker named this rule global access.

      3. When setting up the IPv4 range, use 0.0.0.0/0 to open it to the whole internet.

      4. Create a static IP address. This is important because the external IP address of the server should never change when pointing a website to it.

    5. Pointing a Domain and Enabling HTTPS

      1. Using a domain provider (the speaker used Namecheap for pinkmatcha.co), create an A record that points a domain or subdomain (e.g., n8n.pinkmatcha.co) to the new static IP address.

      2. Install Nginx. Nginx is used to route traffic towards the n8n port (5678):

        sudo apt install nginx
      3. Configure Nginx by creating a configuration and using your specific server name, e.g., n8n.pinkmatcha.co. This allows n8n to be accessed via the website.

        First, open a new file using a text editor (here we use nano):

        sudo nano /etc/nginx/sites-available/n8n

        Then, paste the following content and change the part that says your-domain.com:

        server {
            listen 80;
            server_name your-domain.com;
            location / {
                proxy_pass http://localhost:5678;
                proxy_set_header Connection '';
                proxy_http_version 1.1;
                chunked_transfer_encoding off;
                proxy_buffering off;
                proxy_cache off;
            }
        }

        Link the configuration to the sites-enabled directory:

        sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/

        Test the configuration:

        sudo nginx -t

        Restart nginx with the new configuration:

        sudo systemctl restart nginx
      4. Install Certbot:

        sudo apt install certbot python3-certbot-nginx
      5. Use Certbot to enable HTTPS (secure web access) on your new n8n subdomain:

        sudo certbot --nginx -d your-domain.com
    6. Running n8n in the Background with Docker Compose

      1. To ensure Docker runs even after a system restart, you must set it up to run in the background.

      2. Create an n8n-compose folder.

      3. Create an .env file. In this file, you must change the DOMAIN_NAME to your domain (e.g., n8n.pinkmatcha.co) and update the SSL_EMAIL (e.g., info@pinkmatcha.co).

      4. Create local files to store workflows and credentials.

      5. Create a docker-compose file (compose.yml) which contains the default settings.

      6. Run Docker Compose so the system is configured to start automatically after restart:

        sudo docker compose up
    7. Final Test

      1. Access your n8n subdomain (e.g., n8n.pinkmatcha.co).

      2. Complete the n8n sign-up process to create an owner account.

      3. Create a test workflow with a Webhook node and a Respond to Webhook node.

      4. Configure the response to send a simple text reply, like "Hey there, the setup is complete".

      5. Turn the workflow on.

      6. Open the production URL (the endpoint) to verify that the setup is complete and you receive the "Hey there, the setup is complete" response.

    Leave a Reply

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