Self-hosting n8n gives you complete control over your automation workflows while keeping your data private and costs predictable. This comprehensive guide walks you through every step of setting up a production-ready n8n instance.
Before you invest time in self-hosting, consider trying FlowEngine – we offer a FREE n8n account for personal usage with enhanced features, better UI/UX, and advanced AI integrations. It's n8n on steroids, completely free for personal use. Perfect if you want to start automating immediately without the infrastructure hassle.
Why Choose Self-Hosted n8n?
When you self-host n8n, you're not just saving money—you're gaining unprecedented control over your automation infrastructure. Unlike cloud-based solutions that charge per execution or impose workflow limits, self-hosting means unlimited workflows, unlimited executions, and complete data sovereignty.
Organizations choose self-hosted n8n for several compelling reasons. First, data privacy: your sensitive credentials, API keys, and workflow data never leave your infrastructure. Second, cost predictability: pay only for server resources, not per-automation pricing that can spiral out of control. Third, customization: install custom nodes, modify the source code, and integrate with internal systems that cloud platforms can't access.
The trade-off? You're responsible for infrastructure, security, updates, and maintenance. This guide ensures you get it right from the start.
Prerequisites and System Requirements
Before diving into installation, ensure your infrastructure meets these requirements. For testing and development, 2GB RAM and 1 vCPU suffice. However, production environments should start with 4GB RAM and 2 vCPUs, scaling up based on workflow complexity and execution frequency.
Your server should run a modern Linux distribution—Ubuntu 22.04 LTS is recommended for its stability and long-term support. You'll need Docker and Docker Compose installed, as containerization is the most reliable deployment method. A domain name isn't strictly required, but SSL certificates (essential for production) are far easier with a proper domain.
Don't skip the basics: ensure your server has a firewall configured, SSH key authentication enabled, and automatic security updates configured. These security foundations prevent 90% of common server compromises.
Docker Installation: The Recommended Approach
Docker provides the cleanest, most maintainable n8n installation. Start by installing Docker on your server. On Ubuntu, the official Docker installation script handles everything: curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh
Next, install Docker Compose, which orchestrates multiple containers (n8n plus PostgreSQL for production setups). The latest version can be downloaded directly from GitHub and installed to your system path. Add your user to the docker group to avoid sudo requirements: sudo usermod -aG docker $USER
Create a dedicated directory for n8n: mkdir ~/n8n && cd ~/n8n. This keeps all configuration files, volumes, and backups organized in one location.
Production Docker Compose Configuration
Create a docker-compose.yml file that defines both PostgreSQL (for reliable data storage) and n8n. PostgreSQL is crucial for production—SQLite, while convenient for testing, isn't designed for concurrent access patterns that production workflows generate.
Your compose file should include health checks for PostgreSQL, ensuring n8n doesn't start until the database is ready. Environment variables should be stored in a separate .env file, never committed to version control. Critical variables include database credentials, n8n's encryption key (generate with openssl rand -hex 32), and your domain configuration.
Volume mounts preserve your data across container restarts. Map PostgreSQL data to a named volume and n8n's config directory to persist workflows, credentials, and execution history. Consider adding a local file mount for workflow exports and backups.
SSL Configuration with Nginx and Let's Encrypt
Never run n8n without HTTPS in production. Credentials, API keys, and sensitive data flow through your workflows—encryption isn't optional. Nginx serves as your reverse proxy, handling SSL termination, request buffering, and WebSocket upgrades that n8n's workflows may require.
Install Nginx and Certbot: sudo apt install nginx certbot python3-certbot-nginx. Create an Nginx configuration file in /etc/nginx/sites-available/n8n that proxies requests to n8n's container port (typically 5678). Configure proxy headers correctly—n8n needs to know the original client IP and protocol for webhooks to function properly.
Obtain your SSL certificate with Certbot's automated process: sudo certbot --nginx -d your-n8n-domain.com. Certbot modifies your Nginx configuration, adding SSL directives and setting up automatic renewal. Test renewal with sudo certbot renew --dry-run to ensure certificates won't expire unexpectedly.
Security Hardening Best Practices
Security doesn't end with SSL. Enable n8n's basic authentication or configure SSO through your identity provider. Basic auth is simple but effective: set N8N_BASIC_AUTH_ACTIVE=true along with secure username and password environment variables.
Configure your firewall to allow only necessary ports: SSH (22), HTTP (80), and HTTPS (443). Everything else should be blocked by default. Use fail2ban to automatically block brute-force authentication attempts. Keep your server updated with unattended-upgrades for automatic security patches.
Encrypt your database backups. PostgreSQL contains all your workflow credentials, which are encrypted at rest by n8n but decrypted in database dumps. Store backups in encrypted volumes or use GPG to encrypt backup files before transferring them off-server.
Backup Strategy and Disaster Recovery
Backups aren't optional—they're your insurance policy against hardware failure, accidental deletion, and security incidents. Implement a 3-2-1 backup strategy: three copies of your data, on two different media types, with one copy off-site.
Your backup script should dump the PostgreSQL database daily using pg_dump, archive the n8n data volume (containing workflows and configuration), and transfer both to secure off-site storage. Automate this with a cron job running at low-usage hours. Test your backups monthly by restoring to a test environment—untested backups are worthless.
Document your recovery procedure. When disaster strikes, you won't have time to figure out restoration steps. Your documentation should include exact commands, file locations, and verification steps to confirm successful recovery.
Monitoring and Performance Optimization
Set up monitoring before problems occur. At minimum, monitor disk space, memory usage, CPU load, and n8n's process health. Simple tools like Uptime Kuma can ping your n8n instance and alert you to downtime. More sophisticated setups use Prometheus and Grafana for detailed metrics and beautiful dashboards.
PostgreSQL tuning significantly impacts performance. Adjust shared_buffers to 25% of system RAM, increase effective_cache_size to 50-75% of RAM, and tune connection limits based on your workflow count. n8n's execution queue prevents runaway resource consumption, but PostgreSQL configuration determines how smoothly your workflows execute.
Log rotation prevents disk space exhaustion. Configure Docker's logging driver to limit log file sizes and automatically rotate them. Without this, long-running n8n instances can fill disks with gigabytes of logs, causing unexpected downtime.
The Easier Alternative: FlowEngine
Self-hosting provides maximum control, but it demands significant DevOps expertise and ongoing time investment. Setup takes 4-8 hours if you know what you're doing, potentially days if you're learning. Monthly maintenance—updates, monitoring, troubleshooting—consumes 2-5 hours. That's 30-80 hours annually just managing infrastructure.
FlowEngine eliminates this overhead entirely. We provide fully managed n8n instances free of charge. Zero setup time. Zero maintenance. Automatic backups, security patches, and SSL certificates. Your workflows run on production-grade infrastructure with 99.9% uptime SLA, monitored 24/7 by our team.
Beyond managed hosting, FlowEngine adds AI-powered workflow creation. Describe what you want in plain English—our AI builds the workflow in minutes, not hours. Intelligent debugging identifies issues before they cause failures. Automatic optimization improves workflow performance based on execution patterns.
Self-host if you need absolute control or have specific compliance requirements. For everyone else, FlowEngine delivers better value: all of n8n's power plus AI capabilities, without any of the infrastructure hassle.
Keywords: self-host n8n, n8n docker installation, n8n self-hosted setup, workflow automation hosting, n8n production deployment, docker compose n8n, n8n SSL configuration
