Automation
April 2, 2026
7 min read
13 views

How to Install n8n on an AWS EC2 Server – Step-by-Step Guide

A simple, practical guide to installing n8n on an AWS EC2 Ubuntu server with Nginx reverse proxy, PM2 process management, and free SSL via Let's Encrypt.

n8nAWSEC2AutomationDevOpsNginx
How to Install n8n on an AWS EC2 Server – Step-by-Step Guide

n8n is a powerful open-source workflow automation tool that lets you connect apps, automate tasks, and build AI-powered pipelines — all self-hosted on your own server. In this guide, we walk you through setting up n8n on an AWS EC2 Ubuntu instance with a custom subdomain, HTTPS, and PM2 for auto-restart.

Prerequisites

  • Amazon EC2 instance running Ubuntu (Amazon Linux 2 or similar)
  • SSH access to your instance
  • Security Group with port 5678 open for n8n
  • A domain or subdomain (e.g., n8n.example.com) with an A record pointing to your EC2 public IP
  • nginx installed on the server

Step 1 – Update & Install Essentials

bash
sudo apt update -y
sudo apt upgrade -y
sudo apt install curl nginx unzip -y

Step 2 – Install Node.js (v18)

bash
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
node -v
npm -v

Step 3 – Install PM2 Globally

bash
sudo npm install pm2 -g

Step 4 – Install n8n

bash
sudo npm install -g n8n

Step 5 – Start n8n with PM2

Use PM2 to start n8n so it runs in the background and restarts automatically on reboot.

bash
pm2 start n8n
pm2 startup
pm2 save

Optional: Set environment variables before starting — export N8N_PORT=5678 and export N8N_HOST=localhost — to control which port and host n8n listens on.

Step 6 – Configure Nginx Reverse Proxy

Create an Nginx server block to proxy requests from your subdomain to n8n running on localhost:5678.

bash
sudo nano /etc/nginx/sites-available/n8n

Paste the following configuration (replace n8n.example.com with your actual subdomain):

nginx
server {
    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_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;
    }
}
server {
    if ($host = n8n.example.com) {
        return 301 https://$host$request_uri;
    }
    listen 80;
    server_name n8n.example.com;
    return 404;
}

Enable the configuration and restart Nginx:

bash
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Step 7 – Enable HTTPS with Let's Encrypt (Optional)

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

When prompted, choose redirect to automatically enforce HTTPS. Certbot will update your Nginx config and renew the certificate automatically.

Step 8 – Verify Everything is Running

bash
pm2 list
sudo systemctl status nginx
curl -I http://localhost:5678

Visit https://n8n.example.com in your browser — you should see the n8n login screen.

Useful PM2 Commands

  • pm2 logs n8n — View live n8n logs
  • pm2 restart n8n — Restart the n8n process
  • pm2 stop n8n — Stop n8n without removing it from PM2
  • pm2 list — Check status of all PM2-managed processes

You're done! n8n is now running live on your subdomain with HTTPS enabled and PM2 handling auto-restart on server reboot.

Need help setting up n8n workflows or integrating AI automation into your business? BitPixel Coders builds custom n8n automation pipelines and AI agents — get in touch for a free strategy consultation.

Get a Free Consultation