Requirements
Pada tutorial self hosted n8n serta cara setup domainnya pastikan sudah terinstall
- Docker dan Docker Compose
- Apache
- SSL Let’s Encrypt
Konfigurasi
- Buat folder baru dengan nama n8n-tool
- Di dalam n8n-tool folder, buat file compose.yaml dan masukkan code berikut
services:
n8n:
image: docker.n8n.io/n8nio/n8n
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://n8n.example.com
- GENERIC_TIMEZONE=Asia/Jakarta
volumes:
- n8n_data:/home/node/.n8n
- ./local-files:/files
volumes:
n8n_data:
N8N_HOST dan WEBHOOK_URL: sesuaikan dengaan domain anda
- Kemudian buat folder local-files
- Run
sudo docker compose up -d
Setup Domain untuk n8n
- Buat file baru di
/etc/apache2/sites-available
dengan nama n8n.example.com.conf
<VirtualHost *:80>
ServerName n8n.example.com
</VirtualHost>
- Kemudian aktifkan virtual host dan restart Apache
sudo a2ensite n8n.example.com.conf
sudo systemctl restart apache2
- Buat SSL untuk n8n.example.com dengan run ini
sudo certbot --non-interactive \
-m [email protected] \
--agree-tos \
--no-eff-email \
--apache \
-d n8n.example.com \
--redirect
- Edit konfigurasi setelah membuat SSL selesai (port 443) filenya ada
/etc/apache2/sites-available/n8n.example.com-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName n8n.example.com
SSLCertificateFile /etc/letsencrypt/live/n8n.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/n8n.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
# Preserve original host & scheme for app logic and cookies
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
# Timeouts for long webhook/flows (tune as needed)
ProxyTimeout 600
ProxyBadHeader Ignore
# === Main HTTP proxy to n8n ===
ProxyPass / http://127.0.0.1:5678/
ProxyPassReverse / http://127.0.0.1:5678/
# === WebSocket upgrade (n8n UI uses socket.io) ===
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:5678/$1 [P,L]
ProxyPass /socket.io/ ws://127.0.0.1:5678/socket.io/
ProxyPassReverse /socket.io/ ws://127.0.0.1:5678/socket.io/
</VirtualHost>
</IfModule>
- Kemudian restart apache
sudo systemctl restart apache2
- Selesai Buka browser dan masukkan domain n8n.example.com