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
sudo apt update -y
sudo apt upgrade -y
sudo apt install curl nginx unzip -yStep 2 – Install Node.js (v18)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
node -v
npm -vStep 3 – Install PM2 Globally
sudo npm install pm2 -gStep 4 – Install n8n
sudo npm install -g n8nStep 5 – Start n8n with PM2
Use PM2 to start n8n so it runs in the background and restarts automatically on reboot.
pm2 start n8n
pm2 startup
pm2 saveOptional: 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.
sudo nano /etc/nginx/sites-available/n8nPaste the following configuration (replace n8n.example.com with your actual subdomain):
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:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxStep 7 – Enable HTTPS with Let's Encrypt (Optional)
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d n8n.example.comWhen prompted, choose redirect to automatically enforce HTTPS. Certbot will update your Nginx config and renew the certificate automatically.
Step 8 – Verify Everything is Running
pm2 list
sudo systemctl status nginx
curl -I http://localhost:5678Visit 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