
n8n is an open-source workflow automation tool that enables you to connect various services and automate repetitive tasks through a visual node-based interface. The platform supports many integrations and provides both no-code and low-code capabilities for building complex workflows.
This article explains installing and configuring n8n on Ubuntu 24.04 with Docker, setting up Nginx as a reverse proxy, and securing the installation with TLS certificates.
Prerequisites
Before you begin:
- Access a Ubuntu 24.04 based server as a non-root sudo user.
- Create a domain A record pointing to the instance's public IP address, such as,
n8n.example.com
.
Install Docker and Docker Compose
Update the system packages.
console$ sudo apt update
Install prerequisite packages for Docker repository management.
console$ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Add Docker's official GPG key.
console$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker repository to your system.
console$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the package index.
console$ sudo apt update
Install Docker Engine, CLI, and Docker Compose plugin.
console$ sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
Add your user to the docker group to run Docker commands without sudo.
console$ sudo usermod -aG docker $USER
Apply the group changes to your current terminal session.
console$ newgrp docker
Verify the Docker installation.
console$ docker --version
Create n8n Directory Structure
This section covers setting up a dedicated directory structure for n8n configuration files and data persistence.
Create a directory for n8n.
console$ mkdir ~/n8n
Navigate to the n8n directory.
console$ cd ~/n8n
Create a data directory for n8n persistence.
console$ mkdir n8n-data
Create a directory for local file storage.
console$ mkdir local-files
The n8n container runs with UID 1000. Set proper ownership for the n8n data directory to match the container's user ID.
console$ sudo chown -R 1000:1000 n8n-data local-files
Configure Docker Compose for n8n
In this section, create a Docker Compose configuration file for n8n.
Create a new Docker Compose configuration file.
console$ nano docker-compose.yml
Add the following configuration to the file. Replace
n8n.example.com
with your actual domain.yamlservices: n8n: image: n8nio/n8n:latest container_name: n8n restart: unless-stopped ports: - "5678:5678" environment: - N8N_HOST=n8n.example.com - N8N_PORT=5678 - N8N_PROTOCOL=https - WEBHOOK_URL=https://n8n.example.com - N8N_EDITOR_BASE_URL=https://n8n.example.com - GENERIC_TIMEZONE=UTC - N8N_USER_FOLDER=/home/node/.n8n volumes: - ./n8n-data:/home/node/.n8n - ./local-files:/files networks: - n8n-network networks: n8n-network: driver: bridge
Save and close the file.
The above configuration creates an n8n container with persistent storage, HTTPS protocol settings, and support for webhooks.
Install and Configure Nginx
Nginx serves as a reverse proxy to handle HTTPS termination and forward requests to the n8n container. Install Nginx and create a server block configuration for your domain.
Install Nginx.
console$ sudo apt install nginx -y
Create a new Nginx server block configuration. Replace
n8n.example.com
with your domain.console$ sudo nano /etc/nginx/sites-available/n8n.example.com
Add the following configuration to the file. Replace
n8n.example.com
with your domain.iniserver { listen 80; server_name n8n.example.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_cache_bypass $http_upgrade; 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_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; # WebSocket support proxy_buffering off; # Timeout settings for long-running workflows proxy_read_timeout 300s; proxy_connect_timeout 75s; } }
Save and close the file.
The configuration includes WebSocket support and extended timeouts necessary for n8n's real-time updates and long-running workflows.
Create a symbolic link to enable the site.
console$ sudo ln -s /etc/nginx/sites-available/n8n.example.com /etc/nginx/sites-enabled/
Test the Nginx configuration for syntax errors.
console$ sudo nginx -t
Reload Nginx to apply the configuration.
console$ sudo systemctl reload nginx
Configure Firewall Rules
In this section, configure your firewall rules to allow necessary traffic.
Allow HTTP traffic for initial setup and SSL certificate validation.
console$ sudo ufw allow 80/tcp
Allow HTTPS traffic for secure access.
console$ sudo ufw allow 443/tcp
Install Certbot and Obtain TLS Certificate
Certbot automates TLS certificate generation and renewal using Let's Encrypt. Secure your n8n installation with HTTPS to protect data transmission and enable secure webhook endpoints.
Install Certbot and the Nginx plugin.
console$ sudo apt install certbot python3-certbot-nginx -y
Obtain an TLS certificate for your domain. Replace
n8n.example.com
with your domain andadmin@example.com
with your email address.console$ sudo certbot --nginx -d n8n.example.com --email admin@example.com --agree-tos --non-interactive
Certbot automatically modifies your Nginx configuration to include TLS settings and sets up automatic certificate renewal.
Test automatic certificate renewal.
console$ sudo certbot renew --dry-run
A successful dry run confirms that automatic renewal is configured correctly.
Start n8n
In this section, deploy the n8n container using Docker Compose and verify the installation.
Navigate to the n8n directory.
console$ cd ~/n8n
Start n8n in detached mode.
console$ docker compose up -d
Check the container status.
console$ docker compose ps
View the container logs to verify successful startup.
console$ docker logs n8n
Sample Output:
... n8n ready on https://n8n.example.com
Access and Configure n8n
Complete the initial setup by creating an admin account and configuring basic settings.
Open a web browser and navigate to your n8n domain.
https://n8n.example.com
Create your admin account by providing your email, name, and password.
Access the n8n workflow editor to start creating automations.
You can browse the available workflows from the Templates section, or create your own workflow agent.
Manage n8n Container
Use these commands to manage your n8n installation.
View Logs
Monitor n8n logs in real-time.
$ docker logs -f n8n
Stop n8n
Stop the n8n container.
$ docker compose down
Restart n8n
Restart the n8n container.
$ docker compose restart
Update n8n
Update to the latest n8n version.
$ docker compose pull
$ docker compose up -d
Conclusion
You have successfully installed n8n on Ubuntu 24.04 with Docker, configured Nginx as a reverse proxy, and secured the installation with TLS certificates. Your n8n server is now ready to create workflow automations. The containerized deployment ensures easy maintenance, updates, and scalability as your automation needs grow. For more information, visit the n8n documentation.
No comments yet.