Complete Guide to Self-Hosting n8n on Google Cloud Platform with Auto-Updates
A complete walkthrough of deploying n8n workflow automation platform on Google Cloud Platform with zero monthly costs, automatic updates, and professional SSL setup.
Complete Guide to Self-Hosting n8n on Google Cloud Platform with Auto-Updates
Are you looking to set up your own n8n automation platform without the monthly subscription costs? This comprehensive guide will walk you through hosting n8n on Google Cloud Platform (GCP) with minimal to zero monthly costs, complete with automatic updates and professional SSL configuration.
What You'll Build
By the end of this tutorial, you'll have:
- A fully functional n8n instance running on Google Cloud
- Automatic Docker image updates via cron jobs
- SSL-secured custom domain access
- Professional Nginx reverse proxy setup
- Automated backups before each update
- Zero to minimal monthly costs (depending on usage)
Prerequisites
Before we start, you'll need:
- A credit/debit card for GCP verification
- A domain name you control
- Basic familiarity with Linux command line
- About 1-2 hours of setup time
Why Self-Host n8n?
n8n is a powerful workflow automation tool that can replace expensive SaaS alternatives like Zapier. Self-hosting gives you:
- Cost savings: No monthly subscription fees
- Data privacy: Your workflows and data stay on your infrastructure
- Customization: Full control over environment and configurations
- Scalability: Adjust resources as needed
Part 1: Setting Up Google Cloud Platform
Step 1: Create Your GCP Account
- Navigate to cloud.google.com and click Console
- Click Try for free to start your trial
- Add your payment method to verify identity
- Important: Click Activate full account after verification
Pro Tip: Activating the full account allows continued use after the 90-day trial. Set up budget alerts to control costs.
Step 2: Project Setup
For new accounts, you might need to wait before creating new projects. Alternatively, rename your default "My First Project" for better organization.
Part 2: Creating the VM Instance
Step 1: Enable Compute Engine
- Ensure your project is selected
- Navigate to VM Instances
- Enable the Compute Engine API when prompted
Step 2: Configure Your Free-Tier Instance
To stay within the free tier, your configuration must meet Google's requirements:
Free Tier Limits:
- 1 non-preemptible e2-micro VM per month
- Regions: Oregon (us-west1), Iowa (us-central1), or South Carolina (us-east1)
- 30 GB standard persistent disk
- 1 GB monthly outbound data transfer
- Click Create Instance
- Select E2 machine type and choose e2-micro
- Configure OS and Storage:
- Click Change
- Set Size: 30 GB
- Boot disk type: Standard Persistent Disk
- Name your instance (no spaces) and click Create
Step 3: Configure Static IP Address
To ensure your domain always points to the same IP:
- Navigate to VPC Network > IP addresses
- Find your external IP, click the three dots, and select "Promote to static IP address"
Step 4: Configure Firewall Rules
Enable HTTP and HTTPS traffic for your instance:
Part 3: Installing and Configuring n8n
Step 1: Connect to Your Instance
Click SSH next to your VM instance to open a terminal:
Note: SSH connections may drop frequently. Simply reconnect and continue where you left off.
Step 2: Install Docker
Execute these commands one by one:
# Update package index
sudo apt update
# Install Docker
sudo apt install docker.io
# Start Docker service
sudo systemctl start docker
# Enable Docker to start on boot
sudo systemctl enable docker
Step 3: Configure Domain DNS
Before starting n8n, set up your subdomain:
- Copy your static external IP address
- In your domain provider's DNS settings, create a new A record:
- Type: A
- Name: Your chosen subdomain (e.g., "n8n")
- Points to: Your external IP address
- TTL: 14400 (default)
Step 4: Launch n8n with Docker
Replace your-subdomain.your-domain.com with your actual domain:
sudo docker run -d --restart unless-stopped -it \
--name n8n \
-p 5678:5678 \
-e N8N_HOST="your-subdomain.your-domain.com" \
-e WEBHOOK_TUNNEL_URL="https://your-subdomain.your-domain.com/" \
-e WEBHOOK_URL="https://your-subdomain.your-domain.com/" \
-e N8N_ENABLE_RAW_EXECUTION="true" \
-e NODE_FUNCTION_ALLOW_BUILTIN="crypto" \
-e NODE_FUNCTION_ALLOW_EXTERNAL="" \
-e N8N_PUSH_BACKEND=websocket \
-v /home/$(whoami)/.n8n:/home/node/.n8n \
n8nio/n8n
Part 4: Setting Up Nginx Reverse Proxy
Why Nginx?
Nginx serves as a reverse proxy to:
- Route traffic to n8n securely
- Handle SSL encryption
- Enable custom domain access
- Provide better security and performance
Step 1: Install Nginx
# Install Nginx
sudo apt install nginx
# Create directory structure
sudo mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
Step 2: Configure Nginx
Create the configuration file:
sudo nano /etc/nginx/sites-available/n8n.conf
Add this configuration (replace with your domain):
server {
server_name your-subdomain.your-domain.com;
location / {
proxy_pass http://localhost:5678;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_read_timeout 86400;
}
listen 80;
server_name your-subdomain.your-domain.com;
}
Save with Ctrl + O, Enter, then exit with Ctrl + X.
Step 3: Enable the Configuration
# Create symbolic link
sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/
# Test configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
Part 5: SSL Certificate with Let's Encrypt
Step 1: Install Certbot
sudo apt install certbot python3-certbot-nginx
Step 2: Obtain SSL Certificate
Replace with your actual subdomain and domain:
sudo certbot --nginx -d your-subdomain.your-domain.com
Follow the prompts:
- Enter your email address
- Accept terms of service
- Choose whether to share email with EFF
Step 3: Verify SSL Setup
Visit https://your-subdomain.your-domain.com in your browser:
Congratulations! Your n8n instance is now running with SSL encryption.
Part 6: Automated Updates Setup
To keep your n8n instance updated automatically, we'll create a script that runs weekly via cron.
Step 1: Create Update Script
Note your Google account username from the SSH prompt:
Create the update script:
nano /home/$(whoami)/update_n8n.sh
Add this content (replace mygoogleaccount and domain):
#!/bin/bash
# Backup current n8n directory
BACKUP_DATE=$(date +'%Y-%m-%d_%H-%M-%S')
cp -r /home/$(whoami)/.n8n /home/$(whoami)/.n8n-backup-$BACKUP_DATE
# Stop and remove old container
sudo docker stop n8n
sudo docker rm n8n
# Pull latest n8n version
sudo docker pull n8nio/n8n:latest
# Start new container with correct volume
sudo docker run -d --restart unless-stopped -it \
--name n8n \
-p 5678:5678 \
-e N8N_HOST="your-subdomain.your-domain.com" \
-e WEBHOOK_TUNNEL_URL="https://your-subdomain.your-domain.com/" \
-e WEBHOOK_URL="https://your-subdomain.your-domain.com/" \
-e N8N_ENABLE_RAW_EXECUTION="true" \
-e NODE_FUNCTION_ALLOW_BUILTIN="crypto" \
-e NODE_FUNCTION_ALLOW_EXTERNAL="" \
-e N8N_PUSH_BACKEND=websocket \
-v /home/$(whoami)/.n8n:/home/node/.n8n \
n8nio/n8n
# Clean up old Docker images
sudo docker image prune -af
Step 2: Make Script Executable
chmod +x /home/$(whoami)/update_n8n.sh
Step 3: Setup Weekly Cron Job
Open crontab editor:
sudo crontab -e
Select nano if prompted:
Add these lines:
# Update n8n every Sunday at 3 AM
0 3 * * 0 /bin/bash /home/$(whoami)/update_n8n.sh >> /var/log/update_n8n.log 2>&1
# Clean old backups, keep only 2 most recent
30 3 * * 0 sudo find /home/$(whoami)/.n8n-backup* -maxdepth 0 -type d | sort | head -n -2 | sudo xargs rm -rf
# Fix permissions on reboot
@reboot sudo chown -R 1000:1000 ~/.n8n && sudo chmod -R 777 ~/.n8n
Cron Schedule Explanation:
0 3 * * 0: Run every Sunday at 3:00 AM30 3 * * 0: Clean old backups at 3:30 AM on Sundays@reboot: Fix permissions on system restart
Step 4: Test the Setup
Test the update script manually:
/home/$(whoami)/update_n8n.sh
Since you just installed n8n, it should show "Image is up to date":
Verify backup creation:
ls /home/$(whoami)/ | grep .n8n-backup
Check Docker volume binding:
docker inspect n8n | grep Mounts -A 10
Expected output should include:
"Source": "/home/yourusername/.n8n",
"Destination": "/home/node/.n8n"
Troubleshooting Common Issues
502 Bad Gateway After VM Restart
If you encounter 502 errors after restarting your VM:
- Fix permissions:
sudo chown -R 1000:1000 ~/.n8n
sudo chmod -R 777 ~/.n8n
- Restart n8n container:
sudo docker stop n8n
sudo docker rm n8n
# Run the docker run command again
- Verify n8n is running:
sudo docker ps
Cron Job Not Working
If auto-updates aren't working:
- Create log file with proper permissions:
sudo touch /var/log/update_n8n.log
sudo chmod 666 /var/log/update_n8n.log
- Update cron job to use full path:
0 3 * * 0 /bin/bash /home/yourusername/update_n8n.sh >> /var/log/update_n8n.log 2>&1
- Manual update as fallback:
sudo bash /home/$(whoami)/update_n8n.sh
Path Issues After Updates
After updates, if you see "Cannot GET /home" errors:
- Don't let your browser auto-complete the URL
- Manually enter your full subdomain URL
- The system will redirect to the correct path
Security Considerations
Firewall Configuration
- Only allow necessary ports (80, 443, 22)
- Consider restricting SSH access to specific IP ranges
- Regularly review GCP firewall rules
Data Backup Strategy
- The automated script creates backups before each update
- Consider additional off-site backups for critical workflows
- Test restore procedures periodically
Access Control
- Use strong passwords for your n8n account
- Enable two-factor authentication if available
- Regularly review user access and permissions
Cost Optimization Tips
Monitoring Usage
- Set up GCP budget alerts
- Monitor network egress usage
- Review monthly billing reports
Optimization Strategies
- Use caching in your workflows where possible
- Optimize data transfer patterns
- Consider batch processing for large datasets
Advanced Configuration Options
Environment Variables
The Docker configuration includes several environment variables you can customize:
N8N_ENABLE_RAW_EXECUTION: Allows raw JavaScript executionNODE_FUNCTION_ALLOW_BUILTIN: Enables built-in Node.js modulesNODE_FUNCTION_ALLOW_EXTERNAL: Controls external module accessN8N_PUSH_BACKEND: Sets the push notification backend
Volume Mounting
For persistent data storage beyond workflows:
# Add additional volume mounts for file storage
-v /home/$(whoami)/n8n-files:/files \
Performance Tuning
For high-volume workflows, consider:
- Upgrading to larger VM instances during peak usage
- Implementing database backends for better performance
- Using Redis for caching
Maintenance Best Practices
Regular Tasks
- Weekly: Review automated update logs
- Monthly: Check disk usage and clean up if needed
- Quarterly: Review and update security configurations
Monitoring
Set up basic monitoring to track:
- VM resource usage
- Docker container health
- SSL certificate expiration
- Backup success/failure
Documentation
Keep records of:
- Custom configurations made
- Workflows and their purposes
- Access credentials and their locations
- Incident response procedures
Conclusion
You now have a fully functional, self-hosted n8n automation platform running on Google Cloud Platform with:
✅ Zero to minimal monthly costs (within free tier limits)
✅ Automatic updates every Sunday at 3 AM
✅ SSL-secured custom domain access
✅ Professional Nginx reverse proxy setup
✅ Automated backups before each update
✅ Persistent data storage across updates
This setup provides enterprise-level automation capabilities without the subscription costs, giving you full control over your data and workflows.
Next Steps
- Create your first workflow in the n8n interface
- Set up monitoring for your instance
- Implement additional security measures as needed
- Scale resources if your usage grows
Additional Resources
- n8n Documentation
- Google Cloud Free Tier Details
- Let's Encrypt Documentation
- Nginx Configuration Guide
For more automation tutorials and DevOps guides, check out our other articles on setting up production-ready infrastructure and workflow automation strategies.
This guide is based on the excellent work by Jim Presting in the n8n-gcp-selfhost repository. Special thanks to the StardawnAI YouTube channel for additional insights and community support.
Share this article
Related Articles
Continue your learning journey with these related posts
GitHub Actions Tutorial: Complete CI/CD Guide for Modern Development
Complete GitHub Actions tutorial from basics to advanced CI/CD pipelines. Learn workflows, testing, deployment automation, and best practices.
Complete Docker Tutorial: A Beginner's Guide to Containerization in 2025
Complete step-by-step Docker tutorial covering everything from installation to production deployment. Perfect for beginners wanting to master containerization.
GitHub Actions CI/CD: Complete DevOps Guide for Startups 2025 | Save 70% on CI Costs
Build enterprise-grade CI/CD pipelines with GitHub Actions. Complete startup guide with cost optimization strategies, automated testing workflows, and production deployment patterns that save 70% on CI costs.