no-code guide

no-code guide

No-code

No-code

How to Self-Host Your n8n Easily with Fly.io

Marcelo Abreu | Founder of pdforge

Marcelo | Founder

Marcelo | Founder

Oct 13, 2024

Oct 13, 2024

The Benefits of Self-Hosting n8n

Self-hosting n8n offers significant cost advantages. In today's tech landscape, hosting on your own server is both easy and economical. By self-hosting, you eliminate subscription fees associated with managed services, allowing you to deploy powerful automation workflows at a fraction of the cost.

This approach provides financial flexibility without compromising on performance or capabilities.

Why Fly.io is a Perfect Fit for Deploying n8n

Fly.io excels in providing a containerized infrastructure that simplifies the deployment and maintenance of applications like n8n. Its support for Docker images ensures that updates are seamless, making it effortless to keep your n8n instance current.

Fly.io's edge computing platform brings your application closer to users globally, reducing latency and improving responsiveness. With low prices and extensive documentation, Fly.io empowers developers to deploy, scale, and manage applications with ease.

You can check their complete documentation here.

No-code guide to self-host n8n with fly.io
No-code guide to self-host n8n with fly.io

Preparing to Deploy n8n on Fly.io

Setting Up the Basics: What You Need to Start

Before starting, ensure you have:

  • A Fly.io account

  • The flyctl command-line tool installed

  • Basic command-line proficiency

  • (Optional) Docker installed for local testing

Fly.io Account Creation and Initial Setup

Visit Fly.io and sign up for a new account. After verifying your email, log in to access the dashboard where you can manage applications, monitor logs, and configure settings.

Installing Flyctl: Your Command-Line Companion

Install flyctl using the appropriate command for your operating system:

  • macOS:

  brew install superfly/tap/flyctl
  • Linux:

  curl -L https://fly.io/install.sh | sh
  • Windows (using Chocolatey):

  choco install flyctl

Authenticate flyctl with your Fly.io account:

flyctl auth login

Step-by-Step Guide: Deploying n8n on Fly.io

Configuring Your fly.toml with n8n Docker Image.

Initialize a new Fly.io application:

flyctl launch

Respond to the prompts:

  • App Name: Enter a unique name, e.g., n8n-mycompany.

  • Select Organization: Choose your personal organization.

  • Select Region: Pick a region closest to your user base.

  • Would you like to deploy now?: Select No.

Replace the content of the generated fly.toml file with the following configuration:

# fly.toml file generated for n8n-mycompany on 2024-10-13T17:59:41-03:00
app = "n8n-mycompany"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  image = "n8nio/n8n:latest"
  
[env]
  N8N_USER_FOLDER = "/home/node"
  N8N_HOST = "n8n-mycompany.fly.dev"
  N8N_EDITOR_BASE_URL = "https://n8n-mycompany.fly.dev"
  WEBHOOK_URL = "https://n8n-mycompany.fly.dev"
  EXECUTIONS_DATA_PRUNE = true
  EXECUTIONS_DATA_MAX_AGE = 720
  
[experimental]
  auto_rollback = true
  
[[services]]
  internal_port = 5678
  processes = ["app"]
  protocol = "tcp"
  [services.concurrency]
    type = "connections"
    hard_limit = 120
    soft_limit = 100
  [[services.ports]]
    port = 443
    handlers = ["tls", "http"]
    tls_options = { versions = ["TLSv1.2", "TLSv1.3"] }
  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"
    
[mounts]
  source = "n8n_mycompany_data"
  destination = "/home/node"

Understanding the fly.toml Configuration

  • app: Specifies the application name on Fly.io, set to "n8n-mycompany".

  • kill_signal and kill_timeout: Define the termination signal and timeout period, using "SIGINT" and 5 seconds, respectively.

  • processes: An array to define custom processes; left empty for default behavior.

  • [build]: Indicates the Docker image to deploy, here "n8nio/n8n:latest" ensures the latest n8n version.

  • [env]: Environment variables for n8n:

    • N8N_USER_FOLDER: Sets the user folder to "/home/node" for data persistence.

    • N8N_HOST: The hostname for your n8n instance, matching your Fly.io app name.

    • N8N_EDITOR_BASE_URL: The base URL for accessing the n8n editor interface.

    • WEBHOOK_URL: The public URL where n8n listens for incoming webhooks.

    • EXECUTIONS_DATA_PRUNE: Enables automatic pruning of execution data.

    • EXECUTIONS_DATA_MAX_AGE: Sets the maximum age (in minutes) for execution data retention.

  • [experimental]:

    • auto_rollback: Automatically reverts to the previous deployment if the current one fails.

  • [services]]: Configures network services for the app.

    • internal_port: The internal port n8n listens on, set to 5678.

    • processes: Specifies which processes to route, using ["app"].

    • protocol: Communication protocol, set to "tcp".

  • [services.concurrency]:

    • type: Manages concurrency based on "connections".

    • hard_limit and soft_limit: Define thresholds for scaling.

  • [[services.ports]]:

    • port: Externally exposed port 443 for HTTPS traffic.

    • handlers: Include "tls" and "http" to handle secure connections.

    • tls_options: Specifies supported TLS versions for encryption.

  • [[services.tcp_checks]]:

    • Configures health checks to monitor service availability.

  • [mounts]:

    • source: Names the volume for persistent storage, "n8n_mycompany_data".

    • destination: Mount point inside the container, "/home/node".

Creating Your First Fly.io App for n8n

Deploy the application:

Allocate a public IPv4 address:

Your n8n instance is now accessible at https://n8n-mycompany.fly.dev.

Upgrading Your Fly.io Machine via Command Line

As your application's demands grow, scale your resources accordingly:

This command upgrades your virtual machine to a plan that offers enhanced CPU and memory resources.

Conclusion

Deploying n8n on Fly.io is a streamlined process that combines ease of use with cost efficiency. (You should spend around US$5 per month)

The containerized environment simplifies installation and configuration, allowing you to deploy and update your n8n application seamlessly.

With Fly.io's edge computing capabilities and competitive pricing, you can launch and monitor your n8n instance in just a few minutes, all while keeping operational costs to a minimum.

Generating pdfs at scale can be quite complicated!

Generating pdfs at scale can be quite complicated!

We take care of all of this, so you focus on what trully matters on your Product!

We take care of all of this, so you focus on what trully matters on your Product!

Try for free

7-day free trial

Table of contents

Title