Skip to content

Instantly share code, notes, and snippets.

@delasy
Created August 23, 2022 09:01
Show Gist options
  • Save delasy/9a9c134cd74abfda0affff1a88e1d9bd to your computer and use it in GitHub Desktop.
Save delasy/9a9c134cd74abfda0affff1a88e1d9bd to your computer and use it in GitHub Desktop.
N8N on AWS

N8N on AWS

  1. Create EC2 instance:
  • linux/ubuntu 20.04
  • MINIMUM 2GB RAM
  • Click create
  1. Make sure to add 443 port in security groups
  2. Create Cloudflare domain pointing at server IP address, proxy status - DNS ONLY
  3. SSH to instance and follow instructions:

Install packages

sudo apt-get update -y
sudo apt-get install -y build-essential certbot nginx python3-certbot-nginx

Set environment variables

export AUTOMATION_HOST="n8n.domain.com"
export TECH_EMAIL="[email protected]"

Install Node.js, NPM, PM2, N8N

curl -L https://bit.ly/n-install | bash -s -- -y lts
source ~/.bashrc
npm i -g npm n8n pm2

Configure nginx and SSL

sudo bash -c "cat > /etc/nginx/sites-available/$AUTOMATION_HOST" << EOF
server {
  listen 80;
  listen [::]:80;
  root /var/www/html;
  index index.html index.htm index.nginx-debian.html;
  server_name $AUTOMATION_HOST;
  location / {
    proxy_pass http://localhost:5678;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    proxy_set_header Host \$host;
    chunked_transfer_encoding off;
    proxy_buffering off;
    proxy_cache off;
  }
}
EOF
sudo ln -s /etc/nginx/sites-available/$AUTOMATION_HOST /etc/nginx/sites-enabled/
sudo systemctl restart nginx
sudo certbot --nginx --agree-tos --redirect -d $AUTOMATION_HOST -m $TECH_EMAIL -n

Start n8n and configure launch on server reboot

pm2 start n8n
cat > ecosystem.config.js << EOF
module.exports = {
  apps: [{
    name: "n8n",
    env: {
      N8N_PROTOCOL: "https",
      N8N_HOST: "$AUTOMATION_HOST",
      WEBHOOK_URL: "https://$AUTOMATION_HOST/"
    }
  }]
}
EOF
pm2 start ecosystem.config.js
sudo env PATH=$PATH:/home/ubuntu/n/bin /home/ubuntu/n/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
pm2 save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment