
Sanjay Sikdar

If you want your own automation server (like Zapier, but self-hosted), n8n is perfect.
This guide is step-by-step and covers:
First, we require an ec2 instance so launch an instance with your preferred size, you can also attach an Elastic IP to your instance.
In your DNS Server (Route 53 or Cloudflare) add these records.
| Record Name | Record Type | Value |
|---|---|---|
| n8n | A | [Server_IP] |
| Now, we have pointed from our DNS to our new server IP, now we need to log in into our new server using SSH client. |
Example: ssh -i "YourKey.pem" ubuntu@SERVER_IP
Set a Timezone on Ubuntu:
sudo timedatectl
sudo timedatectl set-timezone Asia/KolkataIf first time using apt in this session, run the update command to update the package manager cache:
sudo apt update -yFollowing Official Docs: https://docs.docker.com/engine/install/ubuntu
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl status dockersudo docker run hello-world
sudo docker versionsudo docker run -it --rm \
--name n8n \
-p 5678:5678 \
-e GENERIC_TIMEZONE="Asia/Kolkata" \
-e TZ="Asia/Kolkata" \
-e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
-e N8N_RUNNERS_ENABLED=true \
-v n8n_data:/home/node/.n8n \
docker.n8n.io/n8nio/n8nYou will see a message indicating that n8n is running on port 5678.
Once you have confirmed that n8n is working correctly, start it in detached mode using the command below:
sudo docker run -d \
--name n8n \
--restart unless-stopped \
-p 127.0.0.1:5678:5678 \
-e GENERIC_TIMEZONE="Asia/Kolkata" \
-e TZ="Asia/Kolkata" \
-e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
-e N8N_RUNNERS_ENABLED=true \
-e N8N_HOST="n8n.example.com" \
-e N8N_PROTOCOL="https" \
-e WEBHOOK_URL="https://n8n.example.com/" \
-e N8N_PROXY_HOPS=1 \
-e N8N_EDITOR_BASE_URL="https://n8n.example.com/" \
-v n8n_data:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
Install Nginx:
sudo apt install nginx
sudo apt install certbot python3-certbot-nginxsudo nano /etc/nginx/sites-available/n8n# WebSocket upgrade mapping
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name n8n.example.com;
location / {
proxy_pass http://127.0.0.1:5678;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $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;
proxy_read_timeout 3600;
proxy_send_timeout 3600;
}
}sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
sudo systemctl status nginxsudo certbot --nginx -d n8n.example.com
sudo systemctl status certbot.timer
sudo certbot renew --dry-runNow, you can request to your domain (http://n8n.example.com)