Back to Blogs

How to Set Up n8n: A Step-by-Step Guide for Self-Hosted Workflow Automation

Workflow automation has become essential for modern businesses and developers seeking to streamline repetitive tasks. While cloud-based solutions offer convenience, self-hosting provides greater control, privacy, and cost-effectiveness for many use cases. n8n stands out as a powerful, open-source workflow automation platform that combines the flexibility of self-hosting with an intuitive visual interface. Unlike proprietary alternatives, […]

You are currently viewing How to Set Up n8n: A Step-by-Step Guide for Self-Hosted Workflow Automation

Workflow automation has become essential for modern businesses and developers seeking to streamline repetitive tasks. While cloud-based solutions offer convenience, self-hosting provides greater control, privacy, and cost-effectiveness for many use cases.

n8n stands out as a powerful, open-source workflow automation platform that combines the flexibility of self-hosting with an intuitive visual interface. Unlike proprietary alternatives, n8n gives you complete ownership of your data and workflows while offering extensive integration capabilities with over 400 services.

This comprehensive guide will walk you through setting up n8n on your own server, from initial installation to creating your first automated workflow. Whether you’re a developer looking to automate deployment processes or a business owner wanting to connect various tools, you’ll have a fully functional n8n instance running by the end of this tutorial.

What Is n8n and Why Should You Use It?

n8n (pronounced “n-eight-n”) is a workflow automation tool that helps you connect different services and automate tasks through a visual node-based interface. Think of it as the open-source alternative to Zapier or Microsoft Power Automate, but with the added benefit of complete control over your installation.

Key benefits of using n8n include:

  • Visual workflow builder: Create complex automations using a drag-and-drop interface without writing code
  • Extensive integrations: Connect with over 400 services including popular tools like Slack, Google Sheets, GitHub, and more
  • Self-hosting advantages: Keep sensitive data on your own servers while avoiding monthly subscription fees
  • Flexibility: Customize the platform to meet specific requirements and add custom nodes
  • Privacy and security: Maintain complete control over your data and workflow execution
  • Cost-effective scaling: Handle unlimited workflows without per-execution pricing

Choosing the Right Deployment: Cloud vs Self-Hosted

Before diving into the setup process, consider your deployment options. n8n offers both cloud-hosted and self-hosted solutions, each with distinct advantages.

Cloud hosting provides immediate access without server management overhead but comes with subscription costs and data privacy considerations. Self-hosting requires more initial setup but offers unlimited usage, complete data control, and significant cost savings for high-volume workflows.

Self-hosting makes sense if you handle sensitive data, need custom integrations, want to avoid ongoing subscription fees, or require specific server configurations.

Prerequisites

Before starting the installation, ensure you have the following requirements:

Server specifications:

  • Ubuntu 20.04 LTS or newer (other Linux distributions work but Ubuntu is recommended)
  • Minimum 2GB RAM (4GB recommended for production use)
  • At least 20GB available disk space
  • Root or sudo access to the server

Additional requirements:

  • Domain name pointed to your server (optional but recommended for HTTPS)
  • Docker and Docker Compose installed
  • Basic familiarity with command-line operations
  • Email address for SSL certificate generation (if using HTTPS)

Installing Docker and Docker Compose:

If Docker isn’t already installed on your server, run these commands:

# Update package index
sudo apt update

# Install Docker
sudo apt install docker.io -y

# Install Docker Compose
sudo apt install docker-compose -y

# Add your user to the docker group
sudo usermod -aG docker $USER

# Log out and back in to apply group changes

Step 1: Create Docker Compose Configuration

Start by creating a dedicated directory for your n8n installation:

mkdir n8n-setup
cd n8n-setup

Create a docker-compose.yml file with the following configuration:

version: '3.8'

services:
  postgres:
    image: postgres:13
    restart: always
    environment:
      POSTGRES_DB: n8n
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: your_secure_password_here
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U n8n -d n8n']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: your_secure_password_here
      N8N_BASIC_AUTH_ACTIVE: true
      N8N_BASIC_AUTH_USER: admin
      N8N_BASIC_AUTH_PASSWORD: your_admin_password_here
      N8N_HOST: your-domain.com
      N8N_PROTOCOL: https
      NODE_ENV: production
      WEBHOOK_URL: https://your-domain.com/
    ports:
      - "5678:5678"
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  postgres_data:
  n8n_data:

Important configuration notes:

  • Replace your_secure_password_here with a strong database password
  • Replace your_admin_password_here with a secure admin password
  • Replace your-domain.com with your actual domain name
  • If you don’t have a domain, you can use your server’s IP address initially

Step 2: Start n8n and Verify Installation

Launch your n8n instance using Docker Compose:

# Start services in detached mode
docker-compose up -d

# Check if services are running
docker-compose ps

# View logs to ensure everything started correctly
docker-compose logs n8n

You should see output indicating that n8n is running on port 5678. Access your installation by navigating to http://your-server-ip:5678 in your web browser.

Initial access notes:

  • You’ll be prompted for basic authentication using the credentials set in your docker-compose.yml
  • The interface may show warnings about insecure cookies over HTTP—this is expected and will be resolved when we configure HTTPS

Step 3: Secure n8n with HTTPS

For production use, securing your n8n instance with HTTPS is crucial. We’ll use Nginx as a reverse proxy with Let’s Encrypt for SSL certificates.

Install Nginx and Certbot:

sudo apt install nginx certbot python3-certbot-nginx -y

Create an Nginx configuration file:

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

Add the following configuration:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        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 $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

Enable the site and obtain SSL certificate:

# Enable the site
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/

# Test Nginx configuration
sudo nginx -t

# Restart Nginx
sudo systemctl restart nginx

# Obtain SSL certificate
sudo certbot --nginx -d your-domain.com

After successful SSL setup, update your docker-compose.yml to reflect the HTTPS configuration, then restart n8n:

docker-compose down
docker-compose up -d

Step 4: Initial Web Interface Setup

Navigate to your secured n8n instance at https://your-domain.com. You’ll be guided through the initial setup process:

Owner account creation:

  1. Create your owner account with a secure email and password
  2. This account has full administrative privileges
  3. Choose a strong password following security best practices

Personalization settings:

  1. Specify your company name and role
  2. Select your primary use case (development, marketing, operations, etc.)
  3. These settings help customize the n8n experience

Optional features:

  • Consider registering for a free community license to access additional features
  • Review available integrations relevant to your use case
  • Familiarize yourself with the main dashboard and navigation

Step 5: Create Your First Workflow

Let’s create a simple workflow to demonstrate n8n’s capabilities:

Creating a webhook-triggered workflow:

  1. Click “New Workflow” from the main dashboard
  2. Add a “Webhook” node as your trigger:
    • Set the HTTP method to “POST”
    • Leave the path as default or customize it
    • Configure authentication if needed
  3. Add a “Set” node to process the incoming data:
    • Connect it to the webhook node
    • Configure fields to extract or transform data from the webhook payload
  4. Add a “HTTP Request” node or notification service:
    • Configure it to send the processed data somewhere useful
    • This could be a Slack message, email notification, or API call
  5. Activate the workflow using the toggle switch
  6. Test using the webhook URL provided by n8n

Testing your workflow:

curl -X POST https://your-domain.com/webhook/your-webhook-path \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello from n8n!"}'

Example Workflow: Server Downtime Recovery and Notification

Here’s a practical example demonstrating n8n’s power for IT automation:

Scenario: Automatically detect server downtime, attempt basic recovery actions, and notify your team.

Workflow components:

  1. Cron trigger: Runs health checks every 5 minutes
  2. HTTP Request node: Pings your application endpoint
  3. IF node: Evaluates response status
  4. SSH node: Executes recovery commands (restart services, clear caches)
  5. Slack/Discord node: Sends notifications to your team
  6. Webhook node: Logs incidents to your monitoring system

This workflow can save precious minutes during outages and ensure your team stays informed about system status changes.

Troubleshooting Common Issues

Authentication problems:

  • Verify basic auth credentials in docker-compose.yml
  • Check that N8N_BASIC_AUTH_ACTIVE is set to true
  • Ensure browser isn’t caching old credentials

SSL/Domain configuration issues:

  • Verify DNS records point to your server
  • Check Nginx configuration syntax with nginx -t
  • Review SSL certificate status with certbot certificates

Performance and resource issues:

  • Monitor system resources with htop or docker stats
  • Increase server memory if workflows are failing
  • Check Docker logs for memory-related errors

Volume and permission problems:

  • Ensure Docker has proper permissions for mounted volumes
  • Check ownership of n8n data directories
  • Verify database connectivity between services

Each of these many content types offers more clarity for the search engine, helping it better comprehend your website’s purpose.

Frequently Asked Questions

Can I migrate from n8n cloud to self-hosted? Yes, n8n provides export/import functionality for workflows. Export your workflows from the cloud version and import them into your self-hosted instance.

How do I backup my n8n installation? Backup both the PostgreSQL database and the n8n data volume. Use docker-compose exec postgres pg_dump for database backups and copy the Docker volumes for workflow data.

What’s the difference between the free and paid features? Self-hosted n8n includes most features for free. Paid licenses primarily add advanced logging, priority support, and some enterprise features.

Can I run n8n without Docker? Yes, but Docker is the recommended approach for easier management and updates. Native installation requires more manual configuration of dependencies.

How do I update my n8n installation? Update the image version in docker-compose.yml, then run docker-compose pull && docker-compose up -d to update to the latest version.

Taking Your Automation Further

With n8n successfully running, you’re ready to explore more advanced automation possibilities. Consider these next steps:

Expand your integration ecosystem by connecting the tools you use daily. Popular workflows include syncing data between CRM systems, automating social media posts, processing form submissions, and managing customer support tickets.

Implement monitoring and alerting workflows that keep you informed about system health, website uptime, and business metrics. These automated checks can prevent small issues from becoming major problems.

Explore advanced features like sub-workflows, error handling, and conditional logic to create more sophisticated automation scenarios. n8n’s visual interface makes it easy to build complex workflows without extensive programming knowledge.

Self-hosting n8n gives you unlimited potential for workflow automation while maintaining complete control over your data and processes. The initial setup investment pays dividends through reduced manual work, improved consistency, and the flexibility to adapt your automations as your needs evolve.

Start small with simple workflows, then gradually build more complex automations as you become comfortable with n8n’s capabilities. Your future self will thank you for the time saved and errors prevented through thoughtful automation.

Book a Free Call –

Ready to set up your self-hosted n8n?

Book a 30-minute session with our experts and get your automation up and running fast.