n8n Self-Hosted Workflow Automation on Ubuntu with Docker Compose
n8n (short for “node everywhere node”) is an open-source workflow automation tool that allows developers to fully control integrations and data processes. In contrast to SaaS solutions like Zapier, n8n can be self-hosted, offering greater flexibility, enhanced data privacy, and improved scalability.
This tutorial walks beginners through the process of installing and setting up n8n on a self-managed Ubuntu server using Docker Compose. It also covers how to fix common setup issues, secure the instance with HTTPS, and prevent typical mistakes when moving to a production environment.
Key Takeaways
Running n8n on your own server is ideal for developers and small teams who want full control, stronger privacy, and the freedom to customize every part of their automation setup. With self-hosting, you avoid vendor lock-in and can shape the environment to match your requirements.
Deploying n8n with Docker Compose on Ubuntu provides a solid, production-grade approach. Docker Compose makes it easier to operate multiple services together (such as the n8n app, a PostgreSQL database, and a reverse proxy), supports straightforward upgrades, and offers restart policies to improve reliability and scaling.
A proper first-time setup typically includes adding PostgreSQL for durable workflow and credential storage, configuring Docker containers for n8n and supporting components, enabling HTTPS via Nginx and Let’s Encrypt for secure access, and creating an owner account to administer the instance. This creates a secure and stable foundation suitable for production.
Protect your deployment by enforcing HTTPS to encrypt traffic, using strong credentials, and configuring environment variables to prevent insecure cookies and exposed ports. For production, you should also limit access, rely on firewalls, and keep containers updated to reduce vulnerability risk.
Activating the free license enables premium-style features such as advanced triggers, more integrations, and priority support for community users. The activation flow is simple and provides additional capabilities without extra costs.
n8n lets you build visual workflows with an easy drag-and-drop editor. You can add triggers (like webhooks or schedules), implement conditional logic, run shell commands, and connect to third-party services (such as Slack, GitHub, or Google Sheets) without writing code.
Example scenario: If you monitor uptime using UptimeRobot and downtime is detected, n8n can automatically run a shell command to attempt recovery and then send real-time notifications to your team through Slack, WhatsApp, or Discord. This cuts manual work and accelerates incident response.
Because the platform is extensible, you can connect n8n with cloud providers (AWS, GCP, Azure), ticketing tools (Jira, Zendesk), and even agentic AI frameworks for intelligent automation. Its modular architecture supports custom nodes, connections to any API, and multi-step workflows that grow with your organization.
By following this guide, you will gain a solid understanding of how to deploy, secure, and expand n8n for a wide range of automation use cases—from basic notifications to complex, AI-powered workflows.
What Is n8n and Why Is It Worth Using?
n8n helps you connect services and automate workflows through a visual interface. It supports integrations with APIs, databases, cloud applications, and custom logic through JavaScript.
Key Features of n8n
n8n is a flexible, developer-oriented automation platform that includes a broad feature set for integration and workflow management:
- Visual Workflow Editor: Build, visualize, and configure advanced automations using a drag-and-drop designer. You can edit nodes, define conditional logic, and watch executions in real time inside the editor, making it easier to design, troubleshoot, and debug workflows without writing code.
- 300+ Integrations: Connect to a wide ecosystem including GitHub, Google Sheets, Slack, MySQL, AWS, Discord, Trello, and more. This enables automation across cloud services, databases, messaging apps, and developer tools.
- Self-Hosting Support: Run n8n on your own infrastructure with Docker, Docker Compose, or directly on bare metal. This provides control over data, security, and scaling, with room for custom configuration to match organizational needs.
- Native JavaScript Functionality: Add custom JavaScript directly in workflows using Function and Function Item nodes. This allows data transformation, business logic, and deeper API interaction beyond standard integrations.
- Event-Driven Execution: Trigger workflows from events like inbound webhooks, scheduled cron runs, changes in connected apps, or manual runs. This model allows automations to react immediately to real-world changes and system events.
- Modular and Extensible Architecture: Create custom nodes, reusable sub-workflows, and extend n8n with community plugins or your own code. This modular approach helps you adapt as your automation requirements change.
- Robust Security and Access Controls: Use authentication, HTTPS, and granular permissions to protect workflows and sensitive data, making n8n suitable for production deployments.
n8n fits well into modern backend stacks by integrating with existing components or introducing new ones, handling scheduled job management, synchronizing data across systems, automating DevOps tasks, supporting internal tool development, and connecting multi-step business flows. Its flexibility and extensibility allow it to support simple automations as well as complex, enterprise-grade workflows.
Selecting the Right Deployment Option: Cloud vs. Self-Hosted
| Option | Pros | Cons | Recommended For |
|---|---|---|---|
| n8n Cloud | No configuration required, fully managed infrastructure, scaling | Requires payment, limited control over the backend | Ideal for non-technical users and quick setup |
| Self-hosted via Docker | Complete control, cost-efficient and secure | Requires initial setup and ongoing server maintenance | Best suited for developers and teams managing their own infrastructure |
| Bare-metal (Node.js) | Maximum flexibility | Requires manual configuration and updates | Best suited for advanced users and specialized use cases |
For many developers and smaller teams, running a self-hosted setup on Ubuntu using Docker offers an ideal mix of control and ease of use.
Requirements
Before getting started, ensure the following requirements are met::
- An Ubuntu 22.04 server (or a more recent version)
- A domain name configured to point to your server
- Root access or a user account with sudo privileges
- Docker and Docker Compose installed
- Optional: An email address for setting up Let’s Encrypt SSL
You can install Docker and Docker Compose with the following commands:
sudo apt update
sudo apt install docker.io docker-compose -y
Step 1 — Set Up the Docker Compose Configuration
Create 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 — Launch n8n and Confirm the Installation
Start the containers:
docker-compose up -d
Accessing n8n
Open your browser and go to:
http://your_server_ip:5678
Alternatively, you can use your domain once DNS and the reverse proxy are configured.
Important
If you open n8n through an IP address or a domain without HTTPS, you might see a browser security warning like this:
HTTP Warning
This occurs because n8n uses secure cookies by default, which require HTTPS. To fix it:
- 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 using HTTPS
We’ll use Nginx and Let’s Encrypt to publish n8n securely over HTTPS.
Install Nginx and Certbot
sudo apt install nginx certbot python3-certbot-nginx -y
Note
To use HTTP only (not recommended for production environments), you can apply the following Nginx configuration 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 use, HTTPS is highly recommended.
Option 2: HTTPS Proxy (Recommended for Production Use)
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 ConfigurationExample of Certbot configuring HTTPS using Nginx for n8n.
Initial n8n Web Interface Setup
After n8n is reachable at https://n8n.yourdomain.com, you’ll see a set of onboarding screens before the main workflow dashboard. Here’s what you’ll go through:
1. Set Up Owner Account
The first screen asks you to create an owner account. You’ll need to provide:
- Email Address
- First and Last Name
- Password (Minimum 8 characters, at least 1 number and 1 capital letter)
This step is necessary to set up the initial admin user for your instance.
2. Configure Your Instance
After creating the account, n8n asks a few optional personalization questions:
- 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 questions help tailor the experience but are not required for functionality.
3. Free Features Registration
You’ll then get the option to unlock select paid-style features (such as execution history, advanced debugging, and folder structure) for free by registering your community instance. You will need to provide your email address to obtain a free license key.
4. License Key Activation
After submitting your email, check your inbox for the license key. You’ll receive a unique activation code that can be used as follows:
- Enter Activation Key
- Navigate to: Settings → Usage and Plan → Enter Activation Key
License Entry PageOnce the key is submitted, your instance will display as Registered, unlocking the advanced features for lifetime use.
These steps complete the initial interface setup and unlock functionality needed for production use.
Step 4 – Create Your First Workflow
Once your n8n instance is available at https://n8n.yourdomain.com, you can build and test your first automation quickly using the web interface:
Step 1: Sign Up
When you visit your domain, you’ll be prompted to sign up and create the 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 assemble your automation.
Step 3: Add a Webhook Trigger
- From the left-hand sidebar, add a Webhook node by dragging it into the workspace.
- Set the HTTP Method to POST.
- Set the Path to test-webhook.
- Click Save.
Step 4: Insert a Response node
- Add a Set node by dragging it into the workspace and connect it to the Webhook node.
- Within the Set node, click on “Add Value” and choose “String”.
- Set the name to message and assign the value “Hello from n8n!”.
Step 5: Activate the Workflow
Toggle the “Active” switch in the top-right corner to enable the workflow.
*
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 everything works correctly, the response will display the message “Hello from n8n!”, and the execution log will be visible in the n8n dashboard.
*
Congratulations, you’ve successfully built your first automated workflow in n8n!
Example Workflow: Server Downtime Recovery and Notification
To show how n8n can be applied to practical automation, here’s a workflow built to handle server or domain outages using UptimeRobot monitoring. This flow detects a failure, runs a shell command to restart services, adjusts DNS or SSL settings in Cloudflare if required, and sends real-time alerts.
Use Case
- Monitor a domain or server with UptimeRobot.
- When a failure is detected, restart Nginx or other services using a shell command.
- Update Cloudflare settings if required, such as changing SSL options or purging the cache.
- Notify teams through WhatsApp and Slack.
- Wait for approval or confirmation via Discord.
- Loop through the monitors to continue monitoring.
Workflow Breakdown
- Schedule Trigger: The Schedule Trigger node automatically begins the workflow on a defined interval, such as every 5 or 10 minutes. This ensures server or domain checks happen consistently without manual effort. By setting the schedule, you can match the check frequency to your operational needs, enabling quick detection of outages or issues. This proactive approach reduces downtime and helps catch problems early before they grow.
- Get Monitor (UptimeRobot): In this step, the workflow uses the UptimeRobot node to connect to the UptimeRobot API and retrieve the latest status of all monitors. It collects real-time information about uptime, response times, and any detected outages. If UptimeRobot reports that a monitored service is unavailable, the workflow continues with the appropriate recovery actions. This integration enables automated monitoring and ensures that decisions are based on the most current service status.
- Execute Command: The Execute Command node uses n8n’s capability to run shell commands directly on your server. When a failure occurs, this node can restart essential services like Nginx, execute custom recovery scripts, or run other administrative actions required to restore availability. Automating these steps reduces manual response during incidents, speeds up recovery, and ensures procedures are applied consistently.
- Cloudflare: This node connects to the Cloudflare API to manage advanced domain-related recovery tasks. For example, it can adjust SSL settings, update DNS records, or purge cached content to address issues caused by misconfigurations or propagation delays. By automating Cloudflare actions within the workflow, a wide range of domain problems can be resolved faster, helping services remain available and secure during complex incidents.
- Send Notifications: The workflow uses parallel nodes to instantly notify relevant team members through Slack and WhatsApp. These alerts provide key incident details, the actions already taken, and any required follow-up steps. Real-time communication keeps everyone informed, supports better coordination, and reduces confusion, helping teams resolve outages more quickly while maintaining full transparency.
- Approval Step (Discord): At this point, the workflow pauses and sends a message to a designated Discord channel to request manual approval from an administrator before proceeding. This adds a human-in-the-loop safety layer, allowing admins to assess the situation, authorize further automated actions, or step in manually if necessary. It is particularly useful for sensitive operations or escalations, providing greater control and accountability.
- Loop Over Items: The final step iterates through all monitored endpoints or services, repeating health checks and recovery actions for each one. This enables the workflow to manage multiple servers or domains within a single execution, making monitoring and remediation more scalable. By checking every item individually, the workflow provides broader coverage and helps resolve infrastructure issues quickly, reducing the risk of unnoticed failures.
Example Workflow
This example shows how n8n supports proactive incident recovery and alerting without human action, unless required. Its modular structure also makes it easy to extend the logic with logging, escalation flows, or integrations with external ticketing systems.
This workflow demonstrates how n8n can serve as a strong self-hosted incident automation solution, improving operational resilience and enabling precise, modular responses to service disruptions.
Troubleshooting Common Errors
| Error | Cause | Solution |
|---|---|---|
| 401 Unauthorized | Missing or incorrect basic auth | Double-check N8N_BASIC_AUTH_* settings |
| Webhook doesn’t trigger | Incorrect domain or DNS configuration | Verify WEBHOOK_TUNNEL_URL is reachable |
| JavaScript heap out of memory | Not enough memory allocated 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 SSL certificate or DNS changes not fully propagated | Wait, retry certbot, and ensure DNS is correct |
Frequently Asked Questions (FAQs)
Q1: What are the prerequisites for installing n8n on Ubuntu?
To set up n8n on an Ubuntu system, you should have a server running Ubuntu 22.04 or a newer version, along with root access or a user account with sudo privileges. A domain name that points to your server’s IP address is also required. Additionally, Docker and Docker Compose must be installed beforehand. For securing your setup with HTTPS, it’s recommended to have an email address available for Let’s Encrypt SSL registration. Ensure your system is fully updated and equipped with enough resources—at least 2 GB of RAM is suggested for smaller deployments.
Q2: What’s the best way to install n8n on Ubuntu for production?
For production environments, using Docker Compose is the preferred approach. It runs n8n and its dependencies—such as PostgreSQL—in isolated containers, simplifying updates, scaling, and backup management. Docker Compose also makes it easy to configure environment variables, persistent storage, and restart policies, helping ensure a stable and production-ready setup.
Q3: How do I secure my n8n instance on Ubuntu with HTTPS?
To enable HTTPS, place a reverse proxy like Nginx in front of your n8n container. You can use Let’s Encrypt to generate a free SSL certificate and configure Nginx to handle HTTPS requests and forward them to n8n. This setup encrypts all communication between users and the platform. It’s also important to use strong authentication credentials and limit access to the admin interface.
Q4: Do I need to use a separate database for n8n on Ubuntu?
Yes, for production use, it’s highly recommended to use an external database such as PostgreSQL instead of the default SQLite. This improves reliability, ensures proper data persistence, and supports better scalability. With Docker Compose, PostgreSQL can be deployed as a separate service with its data stored in persistent volumes for secure backups.
Q5: How can I back up my n8n instance?
Make sure to regularly back up both your n8n_data and postgres_data Docker volumes. For database-level backups, you can create a full PostgreSQL dump using an appropriate pg_dump command. This ensures that all workflows, credentials, and execution data are safely stored and can be restored if needed.
Q6: Can I use n8n with Git for version control?
Yes. Although n8n doesn’t provide built-in Git integration for workflows, you can export workflows as JSON files and store them in a Git repository. This allows you to track changes, manage versions, and collaborate more effectively. For CI/CD pipelines, you can automate the import and export of workflows during deployment.
Q7: How do I upgrade my n8n instance safely?
If you’re using Docker Compose, updating n8n is straightforward. Pull the latest image with docker-compose pull, then restart the services using docker-compose up -d. Before performing the upgrade, always back up your Docker volumes (n8n_data and postgres_data) to avoid potential data loss.
Q8: What’s the difference between active and manual executions in n8n?
Active executions are triggered automatically by real events—such as incoming webhooks or scheduled intervals—once a workflow is activated. Manual executions, on the other hand, are started by clicking “Execute Workflow” during development. While active executions run in the background, manual executions are primarily used for testing and debugging purposes.
Q9: Can I scale n8n for high-volume workflows?
Yes, n8n can be scaled using queue mode. In this configuration, a central queue system (such as Redis) distributes tasks across multiple worker instances. This setup is well-suited for handling high concurrency, including large-scale data processing or frequent API requests. Refer to the official n8n documentation for details on configuring queue mode.
Q10: Is it possible to run multiple workflows in parallel?
Yes, n8n supports running multiple workflows simultaneously, provided your system has sufficient resources. Each execution operates independently, allowing concurrent automation processes without interference.
Conclusion
n8n provides developers with a flexible and powerful platform to automate workflows—ranging from simple email notifications to complex backend orchestration. By deploying n8n on Ubuntu with Docker, you gain full control over your setup while also reducing operational costs.
Once configured, n8n opens up a wide range of use cases across your projects—from automating CI/CD pipelines and monitoring webhooks to integrating advanced AI-driven services.


