Close

Via Don Minzoni, 59 - 73025 - Martano (LE)

n8n self-hosted
AI

n8n Self-Hosted Guide for Zero-Cost Automation

By, effelavio
  • 24 Jul, 2025
  • 61 Views
  • 0 Comment

If you’ve been searching for a powerful and free alternative to automate your workflows, n8n is the ideal solution. This guide will walk you through setting up n8n self-hosted on a local server using Docker, DigitalOcean, and Nginx as a reverse proxy. The main advantage? Unlimited workflows and free access to all essential features.

_Folder Structure

Begin by creating a simple and organized structure:

/opt/n8n
├── data/                  # Persistent n8n data
└── docker/                # Docker configuration and environment variables
    ├── docker-compose.yml
    └── .env

_Docker Compose

Configure your docker-compose.yml file in /opt/n8n/docker as follows:

version: "3.7"

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - N8N_BASIC_AUTH_ACTIVE=${N8N_BASIC_AUTH_ACTIVE}
      - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
      - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
      - N8N_HOST=${N8N_HOST}
      - N8N_PROTOCOL=${N8N_PROTOCOL}
      - WEBHOOK_URL=${WEBHOOK_URL}
    volumes:
      - /opt/n8n/data:/home/node/.n8n

_Environment Variables Configuration

Create the .env file in the same path with this example:

GENERIC_TIMEZONE=Europe/Rome

N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=your-password

N8N_HOST=n8n.yourdomain.com
N8N_PROTOCOL=https
WEBHOOK_URL=https://n8n.yourdomain.com/

_Setting Permissions

Before starting, set the correct permissions:

sudo chown -R 1000:1000 /opt/n8n/data

_Starting n8n

You are now ready to start n8n:

cd /opt/n8n/docker
docker-compose up -d

_Nginx Reverse Proxy Configuration

Configure Nginx to correctly point to your n8n service. Create the file /etc/nginx/sites-available/n8n.yourdomain.com:

server {
    listen 80;
    server_name n8n.yourdomain.com;

    location / {
        return 301 https://$host$request_uri;
    }
}

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;
    ssl_protocols TLSv1.2 TLSv1.3;

    large_client_header_buffers 4 16k;

    location / {
        proxy_pass <http://127.0.0.1:5678/>;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/n8n.yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

_HTTPS Certificate

Install Certbot for free HTTPS:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d n8n.yourdomain.com

Verify automatic certificate renewal:

sudo certbot renew --dry-run

_Operational Notes

  • Self-hosted version: No active workflow limits.
  • Advanced features available for free with a lifetime license.
  • Periodic backups of /opt/n8n/data recommended.
  • Simple updating:
docker-compose pull
docker-compose up -d

_Conclusion

n8n is a comprehensive solution for workflow automation, enabling easy integration with tools like Slack, Notion, Gmail, and over 200 apps. Setup is fast, intuitive, and incredibly flexible, suitable for both less technical users and expert developers. Automate reports, synchronize data, manage notifications, and say goodbye to repetitive manual tasks. Boost your workflows with n8n and transform your working style!