Skip to main content

Setting up n8n automation on the fly.io network

As far as back end automation goes, n8n offers an amazing set of features and plugins. We love to use it so I wanted to create a quick guide on how to self host it easily within just a few steps. This guide assumes that you already have flyctl set up. If not, use our guide on that here.

Architecture Overview

Here's how n8n runs on Fly.io:

graph TB
    subgraph "Internet"
        Users[Users/Webhooks]
        ExtAPI[External APIs]
    end
    
    subgraph "Fly.io Platform"
        Proxy[Fly Proxy<br/>HTTPS Termination]
        
        subgraph "Your App Region"
            Machine[Fly Machine<br/>Auto Start/Stop]
            
            subgraph "Docker Container"
                N8N[n8n Instance<br/>Port 8080]
                SQLite[(SQLite DB)]
            end
            
            Volume[(Persistent Volume<br/>/home/node/.n8n)]
        end
    end
    
    Users -->|HTTPS| Proxy
    Proxy -->|Internal Port 8080| Machine
    N8N <--> SQLite
    SQLite -.->|Persisted| Volume
    N8N <-->|Workflows| ExtAPI
    
    style Volume fill:#90EE90
    style Proxy fill:#87CEEB
    style N8N fill:#FFE4B5

Set up a new fly project

Create a fly.toml file to start your project. You may use the example below. You can adjust the Executions settings if you need more history. I have it like that to save database space.

# fly.toml app configuration file generated for your-n8n-app on 2024-02-01T21:07:37-06:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'your-app-name'
primary_region = 'pick a reagion'

[build]
  image = 'n8nio/n8n'

[env]
  GENERIC_TIMEZONE = 'America/Chicago'
  N8N_DIAGNOSTICS_ENABLED = 'false'
  N8N_HIRING_BANNER_ENABLED = 'false'
  N8N_HOST = 'your-app-name.fly.dev'
  N8N_PORT = '8080'
  N8N_PROTOCOL = 'https'
  TINI_SUBREAPER = 'true'
  WEBHOOK_URL = 'the url to the fly server'
  EXECUTIONS_DATA_PRUNE = 'true'
  EXECUTIONS_DATA_MAX_AGE = '168'
  EXECUTIONS_DATA_PRUNE_MAX_COUNT='10000'

[[mounts]]
  source = 'n8n_vol'
  destination = '/home/node/.n8n'

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1
  processes = ['app']
  
[http_service.concurrency]
  hard_limit = 100
  soft_limit = 50
  type = "connections"

[[vm]]
  cpu_kind = 'shared'
  cpus = 1
  memory_mb = 512

Create a volume to store your database so you don't loose your work between reboots.

flyctl volumes create n8n_vol

Now you can deploy your self hosted instance of n8n.

flyctl deploy

##Update your instance as new releases roll out

The n8n team does an amazing job of rolling out updates so you will want to do this every few weeks or so. This command will get you the latest version installed.

flyctl deploy --no-cache

Need help with your project or have questions?

We specialize in AI automation, custom integrations, and intelligent workflows tailored to your business needs.

Whether you need help deploying, building, implementing, or creating a solution - or just want expert guidance on your project - we're here to help.

Contact us today to discuss your project.