1. Home
  2. Blog
  3. How to Install n8n on a VPS with Docker Compose

How to Install n8n on a VPS with Docker Compose

Learn how to install n8n on a VPS with Docker, a custom domain and HTTPS. It covers requirements, commands, security and settings for stable automations running 24 hours a day.

Automation should not depend on your personal computer being turned on or on a platform limited by monthly task quotas. Knowing how to install n8n on a VPS gives you the freedom to run workflows 24 hours a day, integrate APIs, receive webhooks and keep critical processes under your control. With a Linux VPS, Docker and a configured domain, you can build a professional setup without complex infrastructure.

n8n is a visual automation tool that connects applications, databases, spreadsheets, CRMs, messaging apps and APIs. It works very well on a VPS because it needs continuous availability, especially when your workflows receive external events or run on schedules.

What you need before installing n8n on the VPS

The recommended installation uses Ubuntu, Docker Compose and a reverse proxy to publish the dashboard over HTTPS. For early projects, a VPS with 2 GB of RAM can already handle simple workflows. However, frequent integrations, many webhooks, AI execution, file processing or multiple users require more CPU and memory.

You should also set aside a domain or subdomain, such as `automacao.seudominio.com.br`. It will be used to access the dashboard and receive webhook calls. Using your own domain avoids common URL problems, makes SSL certificate renewal easier and makes the operation more reliable.

Before you start, make sure you have SSH access as the root user or with sudo permissions. A Linux VPS with NVMe SSD helps keep responses fast, especially when n8n stores execution history and works with a database. Unlimited traffic is also useful for automations that exchange large amounts of data with external services.

How to install n8n on a VPS with Docker Compose

Connect to the server through the terminal. On Windows, you can use PowerShell or an SSH client. On macOS and Linux, the native terminal is enough.

Update the system packages:

```bash sudo apt update && sudo apt upgrade -y ```

Install Docker and the Docker Compose plugin:

```bash sudo apt install docker.io docker-compose-plugin -y sudo systemctl enable docker sudo systemctl start docker ```

Now create a dedicated folder for the project. Keeping your files organized makes backups, maintenance and future updates easier.

```bash mkdir -p ~/n8n cd ~/n8n ```

For a small installation, SQLite may work. For professional use, with important automations or expected growth, PostgreSQL is the safer choice. It handles data volume, concurrency and data recovery better.

Create the `docker-compose.yml` file:

```bash nano docker-compose.yml ```

Add this basic structure with n8n and PostgreSQL:

```yaml services: postgres: image: postgres:16 restart: always environment: POSTGRES_USER: n8n POSTGRES_PASSWORD: TROQUE_POR_UMA_SENHA_FORTE POSTGRES_DB: n8n volumes:

  • postgres_data:/var/lib/postgresql/data

n8n: image: n8nio/n8n:latest restart: always ports:

  • "5678:5678"

environment: DB_TYPE: postgresdb DB_POSTGRESDB_HOST: postgres DB_POSTGRESDB_PORT: 5432 DB_POSTGRESDB_DATABASE: n8n DB_POSTGRESDB_USER: n8n DB_POSTGRESDB_PASSWORD: TROQUE_POR_UMA_SENHA_FORTE N8N_HOST: automacao.seudominio.com.br N8N_PROTOCOL: https WEBHOOK_URL: https://automacao.seudominio.com.br/ GENERIC_TIMEZONE: America/Sao_Paulo volumes:

  • n8n_data:/home/node/.n8n

depends_on:

  • postgres

volumes: postgres_data: n8n_data: ```

Replace the database password with a long, unique combination that is hard to guess. Also replace `automacao.seudominio.com.br` with your real domain. Do not publish PostgreSQL port 5432: the database should only be reachable by the internal containers.

Start the services in the background:

```bash docker compose up -d ```

Check whether the containers are running:

```bash docker compose ps ```

At this point, n8n will be running on port 5678. You can temporarily access it at `http://IP-DA-VPS:5678`, but this is not the recommended setup for production. The next step is to secure access with a domain and an SSL certificate.

Configure the domain, reverse proxy and HTTPS

In your domain's DNS panel, create an A record pointing the subdomain to the VPS IP address. Wait for DNS propagation before issuing the certificate. In many cases, this takes a few minutes, but it can vary depending on your DNS provider.

For simple administration, Nginx Proxy Manager is a practical option. It lets you create proxy hosts, issue SSL certificates and redirect HTTP to HTTPS through a web interface. Caddy is also a good choice for leaner setups, since it automates certificates with only a few lines of configuration.

If you prefer traditional Nginx, install it and create a server block that forwards the domain to port 5678. The proxy must pass the correct headers and support persistent connections, since some n8n features use WebSocket.

Then issue the SSL certificate and confirm that the address opens over HTTPS. The `N8N_HOST`, `N8N_PROTOCOL` and `WEBHOOK_URL` variables must exactly match the public URL. If they are wrong, webhooks may be created with an incorrect address, and integrations such as WhatsApp, payment gateways and forms will stop delivering events.

Secure your installation before creating workflows

The first access to the dashboard lets you create the owner account. Use a unique password and enable the security features available in your version of n8n. Do not leave the dashboard exposed only by IP or over HTTP, even if this is a test installation that may receive real data later.

In the firewall, open only the required ports: 22 for SSH, 80 for validation and HTTP redirection, and 443 for HTTPS. Port 5678 does not need to be open to the internet when a reverse proxy sits in front of it.

It is also worth disabling SSH password login and using SSH keys, especially on servers that store API tokens, CRM credentials and customer data. Security is not only about the SSL certificate: it also involves limiting ports, applying updates and reducing unnecessary access.

Backup and updates: what prevents loss of automations

The `n8n_data` volume stores settings and encryption keys. The PostgreSQL volume stores workflows, credentials and execution history. Backing up only one of them can cause data loss or make credentials unreadable after a restore.

The backup frequency depends on how much the automation matters. A workflow that sends weekly reports can accept daily backups. However, an operation that records leads, orders or support tickets in real time deserves more frequent copies and storage outside the VPS.

To update n8n, go to the project folder and run:

```bash cd ~/n8n docker compose pull docker compose up -d ```

Avoid updating directly in a critical operation without a backup and without checking the version first. Read the relevant changes, especially if you use community nodes or sensitive integrations. In some cases, pinning a specific image version is better than using `latest`, because you control when to test and apply new features.

When a VPS for n8n needs more resources

If the dashboard becomes slow, executions pile up or containers keep restarting, your current plan is probably at its limit. Check resource usage with `docker stats` and follow the logs with `docker compose logs -f n8n`. Memory errors, a full disk and timeouts usually show up there before they cause a bigger outage.

The choice of location also depends on the application. A VPS in Brazil can reduce latency for systems, APIs and teams based in Brazil. Integrations that rely mostly on international services may benefit from a location in Canada or Europe. What matters most is combining proximity, sufficient resources and continuous availability.

HostMF offers Linux VPS plans with instant activation, NVMe SSD storage, unlimited traffic, Anti-DDoS protection and 24-hour technical support for anyone who needs to keep automations running. Start with a setup sized for your current volume, monitor your executions and increase resources before your most important workflows feel the growth.

Need a server to put this into practice?

Windows and Linux VPS with instant activation, NVMe SSD and 24/7 support.

View VPS plans
Cookies

By using this site, you automatically agree that we use cookies. For what?

I agree