Report this

What is the reason for this report?

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

Published on July 29, 2025
How to Set Up n8n: A Step-by-Step Guide for Self-Hosted Workflow Automation

Introduction

n8n (also known as “node everywhere node”) is an open-source workflow automation platform that gives developers complete control over integrations and data flows. Unlike SaaS alternatives like Zapier, n8n can be hosted on your own infrastructure, unlocking flexibility, privacy, and scalability.

This tutorial provides a beginner-friendly walkthrough for installing and configuring n8n on a self-hosted Ubuntu server using Docker Compose. You’ll also learn how to resolve common setup errors, secure your instance with HTTPS, and avoid pitfalls during production deployment.

Key Takeaways

  • Self-hosting is recommended for developers and small teams seeking full control, data privacy, and the ability to customize every aspect of their workflow automation. By running n8n on your own infrastructure, you avoid vendor lock-in and can tailor the environment to your specific needs.
  • Docker Compose on Ubuntu offers a robust, production-ready way to deploy n8n. Using Docker Compose simplifies the management of multiple services (like the n8n app, PostgreSQL database, and reverse proxy), enables easy upgrades, and provides built-in restart policies for reliability and scalability.
  • Initial setup includes setup of a PostgreSQL database for persistent workflow and credential storage, configuring Docker containers for n8n and supporting services, setting up HTTPS with Nginx and Let’s Encrypt for secure web access, and creating an owner account to manage your instance. This ensures your automation platform is secure, stable, and ready for production use.
  • Secure your instance by enabling HTTPS to encrypt all traffic, setting strong credentials, and configuring environment variables to avoid insecure cookies and open ports. For production deployments, it’s critical to restrict access, use firewalls, and regularly update your containers to patch vulnerabilities.
  • Free license activation unlocks premium features such as advanced workflow triggers, additional integrations, and priority support for community users. Activating your free license is a simple process and provides access to features that enhance automation capabilities without incurring extra costs.
  • Visual workflows can be built using n8n’s intuitive drag-and-drop editor. You can easily add triggers (like webhooks or scheduled events), set up conditional logic, execute shell commands, and connect to hundreds of third-party services (such as Slack, GitHub, or Google Sheets) without writing code.
  • Example use case: Imagine monitoring your server’s uptime with UptimeRobot. If downtime is detected, n8n can automatically run a shell command to attempt recovery, then send real-time notifications to your team via Slack, WhatsApp, or Discord. This reduces manual intervention and speeds up incident response.
  • Extensible design means you can integrate n8n with cloud platforms (AWS, GCP, Azure), ticketing systems (Jira, Zendesk), and even agentic AI frameworks for intelligent automation. The modular architecture allows you to add custom nodes, connect to any API, and build complex, multi-step workflows that scale with your organization’s needs.

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 starting, ensure you have:

  • An Ubuntu 22.04 server (or newer)
  • A registered domain name pointed to your server
  • Root access or sudo privileges
  • Docker and Docker Compose installed
  • Optional: An email account for Let’s Encrypt SSL

You can install Docker and Docker Compose using:

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

Step 1 — Create Docker Compose Configuration

Set up a directory for your n8n stack:

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

Paste the following minimal setup (PostgreSQL + n8n):

version: '3.7'

services:
  db:
    image: postgres:14
    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:

Step 2 — Start n8n and Verify Installation

Run the containers:

docker-compose up -d

Docker Compose for n8n`*

Accessing n8n

  • Open your browser and go to:

    http://your_server_ip:5678
    
  • Alternatively, use your domain name after DNS and reverse proxy are set up.

Important:
If you access n8n via an IP address or a domain without HTTPS, you may see a browser security warning like this:

HTTP Warning

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

  • Recommended: Use HTTPS with a valid TLS certificate.
  • For local development only: Set the environment variable N8N_SECURE_COOKIE=false (not safe for production).

Step 3 — Secure n8n with HTTPS

We’ll use Nginx and Let’s Encrypt to serve n8n over HTTPS.

Install Nginx and Certbot

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

Note:
If you want to use HTTP only (not recommended for production), you can use the following Nginx config to reverse proxy n8n:

Option 1: HTTP-Only Proxy (for local or insecure setup)

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;
  }
}

For production environments, it’s strongly advised to use HTTPS.

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;
  }
}

Save it as /etc/nginx/sites-available/n8n and enable it:

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

Issue SSL Certificate

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

Certbot SSL Configuration Example of Certbot configuring HTTPS using Nginx for n8n.

Initial n8n Web Interface Setup

Once n8n is running successfully at https://n8n.yourdomain.com, you will be greeted with a sequence of setup screens before reaching the main workflow dashboard. Here’s what to expect:

1. Set Up Owner Account

The first screen prompts you to create an owner account. You will need to enter:

  • Email Address
  • First and Last Name
  • Password (Minimum 8 characters, at least 1 number and 1 capital letter)

This step is required to initialize the admin user for your instance. Owner Account Setup

2. Customize Your Instance

After account creation, n8n asks a few optional questions to personalize your setup:

  • What best describes your company?
  • Which role best describes you?
  • Who will your automations mainly be for?
  • How big is your company?
  • How did you hear about n8n?

These are used to tailor your experience but are not mandatory for functionality.

Personalization Options

3. Free Features Registration

You are then offered a chance to unlock select paid features (like execution history, advanced debugging, and folder structure) for free by registering your community instance. You’ll need to enter your email address to receive a free license key.

Free Features Prompt

4. License Key Activation

After entering your email, check your inbox for a license key. You’ll receive a unique activation code that can be entered as follows:

Enter Activation Key

Navigate to: Settings → Usage and Plan → Enter Activation Key

License Entry Page Once the key is submitted, your instance will show as Registered, unlocking the advanced features for lifetime use.

These initial steps complete the setup of your n8n interface and unlock functionality needed for production use.

Step 4 - Create Your First Workflow

Once your n8n instance is up and running at https://n8n.yourdomain.com, you’ll be able to create and test your first automation in minutes. Here’s how to do it from the web interface:

Step 1: Sign Up

Upon visiting your domain, you’ll be prompted to sign up and create your owner account. This replaces the need for hardcoded credentials in Docker. Sign Up Screen

Step 2: Create a New Workflow

After logging in, click “New Workflow” from the top bar. This opens the visual editor where you’ll build your automation.

Step 3: Add a Webhook Trigger

  1. From the left sidebar, drag in a Webhook node.
  2. Set the HTTP Method to POST.
  3. Set the Path to test-webhook.
  4. Click Save.

Step 4: Add a Response Node

  1. Drag in a Set node and connect it to the Webhook node.
  2. In the Set node, click “Add Value” → “String”.
  3. Enter message as the name and "Hello from n8n!" as the value.

Step 5: Activate the Workflow

Toggle the “Active” switch in the top-right corner to enable the workflow.

![Activate Workflow](https://cdn.yourdomain.com/n8n-setup/activate-placeholder.png)*

Step 6: Trigger the Workflow

Use the following curl command to trigger the workflow:

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

If successful, you’ll see the message "Hello from n8n!" in the response, and the execution log will appear in the n8n dashboard.

![Execution Result](https://cdn.yourdomain.com/n8n-setup/execution-result-placeholder.png)*

Congratulations, you’ve successfully built your first automated workflow in n8n!

Example Workflow: Server Downtime Recovery and Notification

To demonstrate how n8n can be used for real-world automation, here’s a workflow designed to handle server or domain downtime using UptimeRobot monitoring. This setup detects a failure, triggers a shell command to restart services, updates DNS or SSL settings on Cloudflare if needed, and sends real-time alerts.

Use Case

  • Monitor a domain/server using UptimeRobot.

  • On failure detection, restart Nginx or other services via shell command.

  • Update Cloudflare settings (e.g., SSL toggle, cache purge) if needed.

  • Notify teams via WhatsApp and Slack.

  • Await approval or confirmation via Discord.

  • Loop over the monitors for continued monitoring.

Workflow Breakdown

  1. Schedule Trigger
    The Schedule Trigger node is responsible for automatically starting the workflow at predefined intervals, such as every 5 or 10 minutes. This ensures that server or domain health checks are performed consistently without manual intervention. By configuring the schedule, you can tailor the frequency of checks to match your operational needs, allowing for rapid detection of outages or issues. This proactive approach helps minimize downtime and ensures that problems are caught early, before they escalate.

  2. Get Monitor (UptimeRobot)
    In this step, the workflow uses the UptimeRobot node to connect to the UptimeRobot API and retrieve the current status of all configured monitors. The node fetches real-time data about server or domain uptime, response times, and any detected failures. If UptimeRobot reports that a monitored service is down, the workflow branches into remediation steps. This integration allows for seamless, automated monitoring and ensures that the workflow always acts on the latest available information.

  3. Execute Command
    The Execute Command node leverages n8n’s ability to run shell commands directly on your server. When a failure is detected, this node can restart critical services like Nginx, run custom recovery scripts, or perform other administrative tasks needed to restore service. By automating these actions, you reduce the need for manual intervention during incidents, speed up recovery times, and ensure that standard operating procedures are followed consistently every time an issue occurs.

  4. Cloudflare
    This node connects to Cloudflare’s API to perform advanced domain management tasks as part of the recovery process. For example, it can toggle SSL settings, update DNS records, or purge the cache to resolve issues related to misconfigurations or propagation delays. Automating these Cloudflare actions within the workflow helps address a wide range of domain-level problems quickly, ensuring that your services remain accessible and secure even during complex incidents.

  5. Send Notifications
    The workflow uses parallel nodes to send real-time notifications via Slack and WhatsApp to all relevant team members. These alerts include details about the incident, actions taken, and any next steps required. By notifying teams instantly, you ensure that everyone is aware of the situation and can coordinate their response effectively. This rapid communication reduces confusion, speeds up resolution, and helps maintain transparency during outages or critical events.

  6. Approval Step (Discord)
    At this stage, the workflow pauses and sends a message to a designated Discord channel, requesting manual approval from an administrator before proceeding. This step adds a human-in-the-loop safeguard, allowing admins to review the situation, approve further automated actions, or intervene if necessary. It’s especially useful for sensitive operations or when escalation is required, providing an extra layer of control and accountability in the automation process.

  7. Loop Over Items
    The final step involves looping over all monitored endpoints or services, repeating the health check and remediation process for each one. This ensures that the workflow can handle multiple servers or domains in a single run, scaling your monitoring and recovery efforts efficiently. By iterating through each item, you maintain comprehensive coverage and can quickly address issues across your entire infrastructure, reducing the risk of unnoticed failures.

Example Workflow

This example highlights how n8n enables proactive incident recovery and alerting all without human intervention, unless required. The modular design also lets you extend this logic to include logging, escalation workflows, or integration with external ticketing systems.

To learn how such automation principles extend to intelligent agents, refer to our guide on building autonomous systems.

This workflow demonstrates how n8n can be used as a powerful self-hosted incident automation solution, improving operational resilience and enabling precise, modular responses to service disruptions. For developers interested in combining workflow automation with intelligent systems, see our Agentic AI Frameworks Guide.

Troubleshooting Common Errors

Error Cause Solution
401 Unauthorized Missing or incorrect basic auth Double-check N8N_BASIC_AUTH_* settings
Webhook doesn’t trigger Domain/DNS misconfigured Verify WEBHOOK_TUNNEL_URL is reachable
JavaScript heap out of memory Insufficient memory for Node.js Add NODE_OPTIONS=--max-old-space-size=2048
Permissions denied for volumes File system ownership issue sudo chown -R 1000:1000 ./n8n_data
SSL not working Missing cert or DNS not propagated Wait, retry certbot, and ensure DNS is correct

Frequently Asked Questions (FAQs)

Q1: What are the prerequisites for installing n8n on Ubuntu?
To install n8n on Ubuntu, you’ll need an Ubuntu 22.04 (or newer) server with root or sudo privileges, a registered domain name pointed to your server’s IP, and Docker plus Docker Compose installed. It’s also recommended to have an email address for SSL certificate registration (Let’s Encrypt). Make sure your system is up to date and has sufficient resources (at least 2GB RAM for small deployments).

Q2: What’s the best way to install n8n on Ubuntu for production?
The recommended method is using Docker Compose. This approach isolates n8n and its dependencies (like PostgreSQL) in containers, making upgrades, scaling, and backups much easier. Docker Compose also allows you to define environment variables, persistent storage, and restart policies, ensuring your n8n instance is robust and production-ready.

Q3: How do I make my n8n instance on Ubuntu secure with HTTPS?
To secure your n8n instance, set up a reverse proxy (such as Nginx) in front of your n8n Docker container. Use Let’s Encrypt to obtain a free SSL certificate and configure Nginx to forward HTTPS traffic to n8n. This ensures all data between users and your automation platform is encrypted. Additionally, set strong credentials and restrict access to the admin interface.

Q4: Do I need to use a separate database for n8n on Ubuntu?
Yes, for production deployments, it’s strongly recommended to use an external database like PostgreSQL (rather than the default SQLite). This ensures data persistence, reliability, and easier scaling. With Docker Compose, you can run PostgreSQL as a separate service and map its data to a persistent volume for safe backups.

Q5: How can I back up my n8n instance?
Back up both your n8n_data and postgres_data Docker volumes regularly. For database-level backups, you can use the following command to dump all PostgreSQL data:

Q6: Can I use n8n with Git for version control?
Yes. While n8n doesn’t offer native Git integration for workflows, you can export workflows as JSON files and commit them to your Git repository. This enables versioning, change tracking, and collaboration across teams. For CI/CD integration, consider using scripts to import/export workflows during deployment.

Q7: How do I upgrade my n8n instance safely?
To upgrade n8n when using Docker Compose, simply pull the latest image with docker-compose pull and then restart the container using docker-compose up -d. Before upgrading, back up your Docker volumes (n8n_data and postgres_data) to prevent data loss.

Q8: What’s the difference between active and manual executions in n8n?
Active executions are triggered by real-world events (e.g., webhook requests, schedule triggers) when a workflow is “active.” Manual executions occur when you click “Execute Workflow” during development. Active executions run in the background, while manual ones are used for debugging and testing.

Q9: Can I scale n8n for high-volume workflows?
Yes, n8n can be scaled using queue mode. In this setup, a central queue (e.g., Redis) distributes jobs across multiple worker instances. This is ideal for high-concurrency scenarios, such as large-scale data processing or frequent API polling. Check n8n’s documentation for queue mode setup.

Q10: Is it possible to run multiple workflows in parallel?
Yes. n8n supports parallel execution of multiple workflows as long as your server has adequate resources. Each workflow execution is isolated and runs independently, enabling concurrent automation tasks without conflict.

Further Reading

Conclusion

n8n offers developers a powerful, extensible platform for automating workflows from simple email alerts to full-blown backend orchestration. By self-hosting n8n with Docker on Ubuntu, you unlock both control and cost savings.

Set it up once, and you’ll find dozens of use cases across your projects from triggering CI/CD tasks to monitoring webhooks or integrating AI services. You can also explore how agentic workflows power self-directed systems by visiting our Autonomous Systems with Agentic AI guide.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author

Vinayak Baranwal
Vinayak Baranwal
Author
See author profile

Building future-ready infrastructure with Linux, Cloud, and DevOps. Full Stack Developer & System Administrator @ DigitalOcean | GitHub Contributor | Passionate about Docker, PostgreSQL, and Open Source | Exploring NLP & AI-TensorFlow | Nailed over 50+ deployments across production environments.

Still looking for an answer?

Was this helpful?


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.