Skip to Content

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

December 26, 2025 by
How to Set Up n8n: A Step-by-Step Guide for Self-Hosted Workflow Automation
Kais Akram

Introduction

n8n (short for “node everywhere node”) is an open-source workflow automation platform designed for developers who want full control over their integrations and data pipelines. Unlike SaaS tools such as Zapier, n8n can be self-hosted on your own infrastructure, giving you greater flexibility, improved data privacy, and the freedom to scale without platform limitations.

This guide offers a beginner-friendly walkthrough for installing and running n8n on a self-hosted Ubuntu server using Docker Compose. In addition to the basic setup, it covers common installation issues, HTTPS configuration for secure access, and key considerations for running n8n reliably in a production environment.


Key Takeaways

  • Why self-host n8n?
    Running n8n on your own server is ideal for developers and small teams who need complete ownership of their automation stack. Self-hosting eliminates vendor lock-in, improves control over sensitive data, and allows deep customization tailored to your specific workflows.
  • Docker Compose on Ubuntu for production stability
    Docker Compose provides a clean and maintainable way to deploy n8n in production. It simplifies the orchestration of multiple services—such as the n8n application, a PostgreSQL database, and a reverse proxy—while making upgrades, backups, and restarts more manageable.
  • Core components of the initial setup
    A proper deployment includes configuring PostgreSQL for persistent storage of workflows and credentials, setting up n8n containers with the correct environment variables, enabling HTTPS using Nginx and Let’s Encrypt, and creating an initial owner account to manage the instance securely.
  • Security should be a first-class concern
    Encrypting traffic with HTTPS, using strong credentials, and properly configuring environment variables are essential to avoid insecure cookies or exposed ports. In production, firewall rules, restricted access, and regular container updates are critical for maintaining a secure system.
  • Free license activation adds extra capabilities
    Activating n8n’s free license unlocks additional features, including advanced triggers, expanded integrations, and community-priority support. It’s a quick process that enhances automation capabilities without additional cost.
  • Build workflows visually—without heavy coding
    n8n’s visual, drag-and-drop editor allows you to design powerful workflows with ease. You can combine webhooks, scheduled jobs, conditional logic, shell commands, and integrations with services like Slack, GitHub, or Google Sheets—often without writing a single line of code.
  • Practical example: automated incident handling
    Consider a server monitoring setup using UptimeRobot. When downtime is detected, n8n can automatically execute a recovery command and immediately notify your team via Slack, WhatsApp, or Discord. This reduces manual intervention and speeds up incident response.
  • Designed to grow with your automation needs
    n8n’s modular architecture makes it easy to integrate with cloud platforms (AWS, GCP, Azure), ticketing systems (Jira, Zendesk), and even agentic AI frameworks. You can create custom nodes, connect to any REST API, and build complex, multi-step workflows that scale as your organization grows.

By following this guide, you’ll gain a comprehensive understanding of how to deploy, secure, and extend n8n for a wide range of automation scenarios, from simple notifications to advanced, AI-powered workflows.


What Is n8n and Why Should You Use It?

n8n allows you to connect services and automate workflows using a visual interface. You can integrate APIs, databases, cloud apps, and even custom logic using JavaScript.

To explore how intelligent agents can enhance workflow capabilities, check out our Agentic AI Frameworks Guide.

Key Features of n8n

n8n stands out as a flexible, developer-friendly automation platform with a rich set of features designed to streamline integration and workflow management:

  • Visual Workflow Editor: Construct, visualize and configure complex automations with the help of a Drag and Drop designer. You can edit nodes, establish conditional logics, and observe the flow of the execution in real time directly within the editor and do not have a problem designing and debugging workflows without any code.
  • 300+ Integrations: Seamlessly connect with a vast ecosystem of services and applications, including GitHub, Google Sheets, Slack, MySQL, AWS, Discord, Trello, and many more. This extensive library enables you to automate tasks across cloud platforms, databases, messaging apps, and developer tools.
  • Self-Hosting Support: Deploy n8n on your own infrastructure using Docker, Docker Compose, or directly on bare-metal servers. This gives you full control over your data, security, and scaling, and allows for custom configuration to fit your organization’s needs.
  • Native JavaScript Functionality: Insert custom JavaScript code directly into your workflows using the built-in Function and Function Item nodes. This empowers you to transform data, implement business logic, or interact with APIs in ways that go beyond standard integrations.
  • Event-Driven Execution: Trigger workflows based on a wide range of events, such as incoming webhooks, scheduled cron jobs, changes in connected apps, or manual invocations. This event-driven model ensures your automations respond instantly to real-world changes and system events.
  • Modular and Extensible Architecture: Add custom nodes, create reusable sub-workflows, and extend n8n’s capabilities with community plugins or your own code. The modular design makes it easy to adapt n8n to new use cases as your automation needs evolve.
  • Robust Security and Access Controls: Enable authentication, HTTPS, and granular user permissions to protect your workflows and sensitive data, making n8n suitable for production environments.

n8n is the perfect addition to any modern backend stack, integrating with other backend components or introducing new ones, performing scheduled job management, data synchronization between systems, DevOps automation, internal tool development, and multi-step business flows integration. It can be flexible and extensible; therefore, it is capable of supporting simple automations, as well as very complex, enterprise-level workflows.

Choosing the Right Deployment: Cloud vs. Self-Hosted

Option Pros Cons Recommended For
n8n Cloud No setup, managed infra, scaling Paid, limited backend control Non-technical users, quick start
Self-hosted via Docker Full control, cost-effective, secure Requires setup, server maintenance Developers, teams with infrastructure
Bare-metal (Node.js) Maximum flexibility Manual config and updates Advanced users, edge use cases

For most developers and small teams, Docker-based self-hosting on Ubuntu offers the best mix of control and simplicity.


Prerequisites

Before proceeding with the installation, make sure your environment meets the following requirements:

  • An Ubuntu server running 22.04 or later
  • A domain name already pointing to your server’s public IP
  • Root access or a user with sudo privileges
  • Docker and Docker Compose installed on the system
  • (Optional but recommended) A valid email address for issuing a Let’s Encrypt SSL certificate

If Docker and Docker Compose are not yet installed, you can set them up quickly by running the commands below:

sudo apt update sudo apt install docker.io docker-compose -y

Once the installation is complete, you’ll be ready to move on to configuring n8n and its supporting services.


Step 1 — Create the Docker Compose Configuration

To begin, create a dedicated directory for your n8n deployment and move into it:

mkdir ~/n8n && cd ~/n8n nano docker-compose.yml

Now add a minimal but production-ready Docker Compose configuration that includes PostgreSQL for persistence and n8n as the automation engine.

version: "3.7" services: db: image: postgres:17 environment: POSTGRES_USER: n8n POSTGRES_PASSWORD: n8npass POSTGRES_DB: n8n volumes: - postgres_data:/var/lib/postgresql/data n8n: image: n8nio/n8n ports: - "5678:5678" environment: DB_TYPE: postgresdb DB_POSTGRESDB_HOST: db DB_POSTGRESDB_DATABASE: n8n DB_POSTGRESDB_USER: n8n DB_POSTGRESDB_PASSWORD: n8npass N8N_BASIC_AUTH_ACTIVE: "true" N8N_BASIC_AUTH_USER: admin N8N_BASIC_AUTH_PASSWORD: strongpass N8N_HOST: n8n.yourdomain.com WEBHOOK_TUNNEL_URL: https://n8n.yourdomain.com depends_on: - db volumes: - n8n_data:/home/node/.n8n volumes: postgres_data: n8n_data:

Note:

For production environments, avoid hardcoding credentials. Use .env files or Docker secrets instead.

Step 2 — Start n8n and Verify the Installation

Start all services in detached mode:

docker-compose up -d

Once the containers are running, access n8n in your browser:

http://YOUR_SERVER_IP:5678

You can later switch to your domain once DNS and HTTPS are configured.

Common HTTPS Warning

If you access n8n over HTTP or via IP, you may see a browser warning.

This happens because n8n uses secure cookies by default, which require HTTPS.

How to resolve it:

  • Recommended (Production): Enable HTTPS with a valid TLS certificate
  • ⚠️ Local development only:

  • N8N_SECURE_COOKIE=false

    (Do not use this in production)

Step 3 — Secure n8n with HTTPS (Nginx + Let’s Encrypt)

To secure your instance, place n8n behind Nginx and issue a free SSL certificate using Let’s Encrypt.

Install Required Packages

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

Option A — HTTP Reverse Proxy (Not Recommended)

Useful only for testing or internal environments.

server { listen 80; server_name n8n.yourdomain.com; location / { proxy_pass http://localhost:5678; 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; } }

Option B — HTTPS Reverse Proxy (Recommended)

server { listen 443 ssl; server_name n8n.yourdomain.com; ssl_certificate /etc/letsencrypt/live/n8n.yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/n8n.yourdomain.com/privkey.pem; location / { proxy_pass http://localhost:5678; 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; } }

Enable the site and reload Nginx:

sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx

Issue the SSL Certificate

sudo certbot --nginx -d n8n.yourdomain.com

Once completed, your instance will be accessible at:

https://n8n.yourdomain.com

Initial n8n Web Interface Setup

When you first access n8n, a guided setup process will appear.

1. Create the Owner Account

You’ll be prompted to define the main administrator:

  • Email address
  • Full name
  • Password (minimum 8 characters, at least one number and uppercase letter)

This account has full control over the instance.

2. Optional Personalization

n8n may ask optional questions about your role, company size, and intended use.

These do not affect functionality and can be skipped.

3. Activate Free Licensed Features

You can unlock additional features (execution history, folders, debugging tools) by registering your community license.

After entering your email, you’ll receive an activation key.

Go to:

Settings → Usage and Plan → Enter Activation Key

Once activated, your instance will show as Registered.

Step 4 — Create Your First Workflow

Create a Simple Webhook Automation

  1. Click New Workflow
  2. Add a Webhook node
    • Method: POST
    • Path: test-webhook
  3. Add a Set node
    • Field name: message
    • Value: "Hello from n8n!"
  4. Connect the nodes
  5. Activate the workflow

Trigger it using:

curl -X POST https://n8n.yourdomain.com/webhook/test-webhook

You should receive:

{ "message": "Hello from n8n!" }

🎉 Your first automation is live.

Example Workflow — Automated Downtime Recovery

This real-world scenario demonstrates incident detection and recovery using n8n.

Use Case Overview

  • Monitor uptime with UptimeRobot
  • Restart services automatically via shell command
  • Update Cloudflare settings if required
  • Notify teams via Slack & WhatsApp
  • Request approval via Discord
  • Loop through all monitored services

Key Workflow Components

  • Schedule Trigger — runs health checks periodically
  • UptimeRobot Node — retrieves monitor status
  • Execute Command — restarts services automatically
  • Cloudflare API — manages DNS / SSL / cache
  • Notification Nodes — Slack & WhatsApp alerts
  • Approval Step — human-in-the-loop via Discord
  • Loop Over Items — handles multiple servers/domains

This design enables proactive recovery, minimizing downtime and manual effort.

Troubleshooting Common Issues

ErrorCauseSolution
401 UnauthorizedIncorrect auth credentialsVerify N8N_BASIC_AUTH_*
Webhook not firingDNS or URL issueCheck WEBHOOK_TUNNEL_URL
JavaScript heap errorLow memoryNODE_OPTIONS=--max-old-space-size=2048
Volume permission deniedOwnership mismatchsudo chown -R 1000:1000 ./n8n_data
SSL not workingDNS not propagatedWait and retry Certbot

Conclusion

n8n is a powerful, flexible automation platform that shines when self-hosted.

By deploying it on Ubuntu with Docker Compose, you gain full control, better security, and lower long-term costs.

From simple notifications to advanced, agent-driven automation, n8n scales with your needs and integrates seamlessly with modern infrastructure.

Set it up once — and let automation do the rest 🚀