Skip to content

iam-joey/n8n-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

N8N Installation Script for Ubuntu

πŸš€ One-command installation script for n8n with Docker, Nginx, and SSL certificates.

πŸ“‹ Table of Contents

πŸ” Overview

This script provides a complete automated installation of n8n (workflow automation tool) with:

  • βœ… Docker containerization
  • βœ… Nginx reverse proxy
  • βœ… SSL certificate (Let's Encrypt)
  • βœ… Automatic HTTPS redirect
  • βœ… Production-ready configuration

πŸ’» Supported Operating Systems

  • Ubuntu 24.04 LTS (Recommended)
  • Ubuntu 22.04 LTS
  • Ubuntu 20.04 LTS

Note: This script is specifically designed for Ubuntu and has been tested on fresh Ubuntu instances.

πŸ› οΈ Prerequisites

1. Fresh Ubuntu Instance

  • Use a new, clean Ubuntu server for best results
  • Minimum 1GB RAM, 1 CPU core
  • At least 10GB storage space

2. Domain Name

  • You must own a domain name (e.g., yourdomain.com)
  • Can be a root domain (joey.com) or subdomain (hello.joey.com)
  • Domain must be pointed to your server's IP address

3. Server Requirements

  • Root access or user with sudo privileges
  • Internet connection for downloading packages
  • Ports 80 and 443 must be accessible from the internet

4. Email Address

  • Valid email address for SSL certificate registration

πŸš€ Installation Steps

Step 1: Switch to Root User

⚠️ IMPORTANT: Switch to root user before proceeding:

sudo su

Step 2: Update Your System

⚠️ IMPORTANT: Always update your system before running the script:

apt update && apt upgrade -y

Step 3: Configure DNS

Before running the script, ensure your domain points to your server:

For Root Domain (e.g., joey.com):

  1. Go to your domain registrar (GoDaddy, Cloudflare, etc.)
  2. Create an A record: @ β†’ your-server-ip
  3. Wait for DNS propagation (5-60 minutes)
  4. Test DNS: nslookup joey.com

For Subdomain (e.g., hello.joey.com):

  1. Go to your domain registrar (GoDaddy, Cloudflare, etc.)
  2. Create an A record: hello β†’ your-server-ip
  3. Wait for DNS propagation (5-60 minutes)
  4. Test DNS: nslookup hello.joey.com

Step 4: Configure Firewall

Ensure ports 80 and 443 are open:

# Enable firewall
ufw enable

# Allow HTTP and HTTPS
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 22/tcp

# Check status
ufw status

Step 5: Download and Run the Script

# Download the script
wget https://raw.githubusercontent.com/iam-joey/n8n-script/main/script.sh

# Make it executable
chmod +x script.sh

# Run the installation
./script.sh --domain="yourdomain.com" --email="your-email@gmail.com"

πŸ“– Usage

Basic Usage

./script.sh --domain="yourdomain.com" --email="your-email@gmail.com"

Help

./script.sh --help

Examples

Root Domain:

./script.sh --domain="joey.com" --email="admin@joey.com"

Subdomain:

./script.sh --domain="n8n.joey.com" --email="admin@joey.com"
./script.sh --domain="hello.joey.com" --email="admin@joey.com"
./script.sh --domain="automation.joey.com" --email="admin@joey.com"

πŸ”„ What This Script Does

Phase 1: System Prerequisites

  • βœ… Checks root/sudo privileges
  • βœ… Installs Docker and Docker Compose
  • βœ… Installs Nginx web server
  • βœ… Installs Certbot for SSL certificates
  • βœ… Configures all services

Phase 2: N8N Docker Deployment

  • βœ… Validates domain and email format
  • βœ… Checks for existing n8n containers
  • βœ… Verifies DNS configuration
  • βœ… Pulls and deploys n8n container
  • βœ… Configures n8n with your domain
  • βœ… Tests local accessibility

Phase 3: SSL & Public Access

  • βœ… Configures Nginx reverse proxy
  • βœ… Generates SSL certificate
  • βœ… Enables HTTPS with auto-redirect
  • βœ… Tests public accessibility
  • βœ… Sets up automatic SSL renewal

πŸ›‘οΈ Firewall Configuration

Ubuntu UFW (Uncomplicated Firewall)

ufw enable
ufw allow 22/tcp    # SSH
ufw allow 80/tcp    # HTTP
ufw allow 443/tcp   # HTTPS

AWS Security Groups

If using AWS EC2, configure Security Groups:

  • HTTP (80): Source 0.0.0.0/0
  • HTTPS (443): Source 0.0.0.0/0
  • SSH (22): Source your-ip/32

Google Cloud Firewall

# Allow HTTP traffic
gcloud compute firewall-rules create allow-http --allow tcp:80 --source-ranges 0.0.0.0/0

# Allow HTTPS traffic
gcloud compute firewall-rules create allow-https --allow tcp:443 --source-ranges 0.0.0.0/0

🌐 DNS Configuration

For Root Domain (e.g., joey.com)

Create an A record in your domain's DNS settings:

Type Name Value TTL
A @ your-server-ip 300
A www your-server-ip 300

For Subdomain (e.g., hello.joey.com)

Create an A record for the subdomain:

Type Name Value TTL
A hello your-server-ip 300

Alternative: CNAME Record for Subdomain

Type Name Value TTL
CNAME hello joey.com 300

DNS Record Comparison

Method Pros Cons Best For
A Record Direct IP pointing, faster resolution Need to update if IP changes Most common, reliable
CNAME Record Follows main domain changes automatically Extra DNS lookup step When IP might change frequently

Common Subdomain Examples

  • n8n.yourdomain.com - Clear purpose identification
  • automation.yourdomain.com - Descriptive naming
  • workflows.yourdomain.com - Business-focused naming
  • app.yourdomain.com - Generic application naming

Verify DNS

For Root Domain:

# Check if domain resolves to your server
nslookup joey.com
dig joey.com

# Should return your server's IP address

For Subdomain:

# Check if subdomain resolves to your server
nslookup hello.joey.com
dig hello.joey.com

# Should return your server's IP address (A record) or main domain (CNAME)

πŸ”§ Troubleshooting

Common Issues

1. SSL Certificate Generation Fails

Error: Timeout during connect (likely firewall problem)

Solution:

  • Ensure ports 80/443 are open in firewall
  • Check cloud provider security groups
  • Verify DNS is properly configured

2. Docker Permission Denied

Error: permission denied while trying to connect to the Docker daemon

Solution:

# Add user to docker group
usermod -aG docker $USER

# Logout and login again, or run:
newgrp docker

3. Domain Not Resolving

Error: Failed to resolve domain

Solution:

  • Wait for DNS propagation (up to 60 minutes)
  • Check DNS configuration at your registrar
  • Use nslookup to verify DNS resolution

4. Existing N8N Container

Error: An n8n container already exists

Solution:

# Stop and remove existing container
docker stop n8n
docker rm n8n

# Run script again
./script.sh --domain="yourdomain.com" --email="your-email@gmail.com"

πŸ› οΈ Management Commands

N8N Container Management

# Check n8n status
docker ps --filter name=n8n

# View n8n logs
docker logs n8n

# Restart n8n
docker restart n8n

# Stop n8n
docker stop n8n

# Start n8n
docker start n8n

SSL Certificate Management

# Check SSL certificate status
certbot certificates

# Renew SSL certificate manually
certbot renew

# Test SSL renewal
certbot renew --dry-run

Nginx Management

# Check nginx status
systemctl status nginx

# Restart nginx
systemctl restart nginx

# Test nginx configuration
nginx -t

# View nginx error logs
tail -f /var/log/nginx/error.log

πŸ”’ Security Notes

SSL Certificate

  • βœ… SSL certificates auto-renew every 90 days
  • βœ… HTTP traffic automatically redirects to HTTPS
  • βœ… Strong SSL configuration with modern ciphers

Data Security

  • βœ… N8N data stored in ~/.n8n directory
  • βœ… Automatic backups recommended
  • βœ… Regular security updates advised

Firewall Security

  • βœ… Only essential ports (22, 80, 443) should be open
  • βœ… SSH access should be restricted to your IP
  • βœ… Regular security audits recommended

πŸ“š Additional Resources

🀝 Support

If you encounter issues:

  1. Check the Troubleshooting section
  2. Review the script logs carefully
  3. Ensure all prerequisites are met
  4. Verify firewall and DNS configuration

πŸ“„ License

This script is provided as-is for educational and production use. Please review and test in a development environment before production deployment.


πŸŽ‰ Happy Automating with N8N!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages