├── ssl.png └── README.md /ssl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bilalnaseer/n8n-free/HEAD/ssl.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Youtube Tutorial 2 | [![Install N8N For Free](https://img.youtube.com/vi/x49ZiJDIVPQ/0.jpg)](https://www.youtube.com/watch?v=x49ZiJDIVPQ) 3 | 4 | 5 | # Self-Hosting SSL enabled N8N on a Linux Server 6 | 7 | This guide provides step-by-step instructions to self-host [n8n](https://n8n.io), a free and open-source workflow automation tool, on a Linux server using Docker, Nginx, and Certbot for SSL with a custom domain name. 8 | 9 | 10 | 11 | ## Step 1: Installing Docker 12 | 13 | 1. **Update the Package Index:** 14 | ```bash 15 | sudo apt update 16 | 17 | 2. **Install Docker:** 18 | ```bash 19 | sudo apt install docker.io 20 | 21 | 3. **Start Docker:** 22 | ```bash 23 | sudo systemctl start docker 24 | 25 | 4. **Enable Docker to Start at Boot:** 26 | ```bash 27 | sudo systemctl enable docker 28 | 29 | 30 | ## Step 2: Starting n8n in Docker 31 | 32 | **Run the following command to start n8n in Docker. Replace your-domain.com with your actual domain name:** 33 | 34 | ```bash 35 | sudo docker run -d --restart unless-stopped -it \ 36 | --name n8n \ 37 | -p 5678:5678 \ 38 | -e N8N_HOST="your-domain.com" \ 39 | -e WEBHOOK_TUNNEL_URL="https://your-domain.com/" \ 40 | -e WEBHOOK_URL="https://your-domain.com/" \ 41 | -v ~/.n8n:/root/.n8n \ 42 | n8nio/n8n 43 | ``` 44 | 45 | **Or if you are using a subdomain, it should look like this:** 46 | 47 | ```bash 48 | sudo docker run -d --restart unless-stopped -it \ 49 | --name n8n \ 50 | -p 5678:5678 \ 51 | -e N8N_HOST="subdomain.your-domain.com" \ 52 | -e WEBHOOK_TUNNEL_URL="https://subdomain.your-domain.com/" \ 53 | -e WEBHOOK_URL="https://subdomain.your-domain.com/" \ 54 | -v ~/.n8n:/root/.n8n \ 55 | n8nio/n8n 56 | ``` 57 | 58 | 59 | This command does the following: 60 | 61 | - Downloads and runs the n8n Docker image. 62 | - Exposes n8n on port 5678. 63 | - Sets environment variables for the n8n host and webhook tunnel URL. 64 | - Mounts the n8n data directory for persistent storage. 65 | - After executing the command, n8n will be accessible on your-domain.com:5678. 66 | 67 | ## Step 3: Installing Nginx 68 | 69 | Nginx is used as a reverse proxy to forward requests to n8n and handle SSL termination. 70 | 71 | 1. **Install Nginx:** 72 | ```bash 73 | sudo apt install nginx 74 | 75 | ## Step 4: Configuring Nginx 76 | 77 | Configure Nginx to reverse proxy the n8n web interface: 78 | 79 | 1. **Create a New Nginx Configuration File:** 80 | ```bash 81 | sudo nano /etc/nginx/sites-available/n8n.conf 82 | 83 | 2. **Paste the Following Configuration:** 84 | ```bash 85 | server { 86 | listen 80; 87 | server_name your-domain.com; // subdomain.your-domain.com if you have a subdomain 88 | 89 | location / { 90 | proxy_pass http://localhost:5678; 91 | proxy_http_version 1.1; 92 | chunked_transfer_encoding off; 93 | proxy_buffering off; 94 | proxy_cache off; 95 | proxy_set_header Upgrade $http_upgrade; 96 | proxy_set_header Connection "upgrade"; 97 | proxy_set_header Host $host; 98 | proxy_set_header X-Real-IP $remote_addr; 99 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 100 | proxy_set_header X-Forwarded-Proto https; 101 | proxy_read_timeout 86400; 102 | } 103 | } 104 | ``` 105 | Replace your-domain.com with your actual domain. 106 | 107 | 3. **Enable the Configuration:** 108 | ```bash 109 | sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/ 110 | 111 | 4. **Test the Nginx Configuration and Restart:** 112 | ```bash 113 | sudo nginx -t 114 | sudo systemctl restart nginx 115 | ``` 116 | 117 | ## Step 5: Setting up SSL with Certbot 118 | 119 | Certbot will obtain and install an SSL certificate from Let's Encrypt. 120 | 121 | 1. **Install Certbot and the Nginx Plugin:** 122 | ```bash 123 | sudo apt install certbot python3-certbot-nginx 124 | 125 | 2. **Obtain an SSL Certificate:** 126 | ```bash 127 | sudo certbot --nginx -d your-domain.com 128 | // If you have a subdomain then it will be subdomain.your-domain.com 129 | 130 | Follow the on-screen instructions to complete the SSL setup. 131 | Once completed, n8n will be accessible securely over HTTPS at your-domain.com. 132 | 133 | IMPORTANT: Make sure you follow the above steps in order. Step 5 will modify your /etc/nginx/sites-available/n8n.conf file to something like this: 134 | 135 | ![image](/ssl.png) 136 | 137 | 138 | 139 | By using Nginx and Certbot, you ensure that your n8n instance is securely accessible over the internet with HTTPS. 140 | 141 | --------------------------------------------------------------------------------