n8n Server Setup: Ubuntu 24 + Nginx Reverse Proxy + Public Domain


## Hosting n8n on Ubuntu 24.04 with Nginx Reverse Proxy
### **Prerequisites**
1. **Server Requirements**:
- **CPU**: Minimum 10 CPU cycles (small cloud instances like AWS/GCP suffice).
- **Memory**: 320 MB–2 GB (idle usage ~100 MB; scales with workflow complexity).
- **Database**: SQLite (default) or PostgreSQL (recommended for production, 512 MB–4 GB SSD).
- **OS**: Ubuntu 24.04 with root/sudo access.
- **Domain**: A public domain (e.g., `n8n.yourdomain.com`) pointing to your server’s IP.
2. **Dependencies**:
- Node.js (LTS version, e.g., v20.x) and npm.
- Nginx (for reverse proxy and HTTPS).
- PostgreSQL (optional but recommended for production).
---
### **Installation Steps**
#### **1. Update System & Install Node.js**
```bash
sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs
sudo npm install -g npm@latest # Update npm
2. Install n8n Globally
sudo npm install -g n8n
3. Configure PostgreSQL (Optional)
sudo apt install postgresql postgresql-contrib
sudo -u postgres psql
CREATE DATABASE n8n;
CREATE USER n8n_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE n8n TO n8n_user;
\q
Set environment variables for n8n to use PostgreSQL:
export DB_TYPE=postgresdb
export DB_POSTGRESDB_DATABASE=n8n
export DB_POSTGRESDB_USER=n8n_user
export DB_POSTGRESDB_PASSWORD=your_password
export DB_POSTGRESDB_HOST=localhost
4. Set Up Nginx Reverse Proxy
Install Nginx:
sudo apt install nginx -y
Create a configuration file for your domain:
sudo nano /etc/nginx/sites-available/n8n.conf
Add the following (replace n8n.yourdomain.com
with your domain and SSL paths):
server {
listen 80;
server_name n8n.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name n8n.yourdomain.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://localhost:5678;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Enable the configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/n8n.conf /etc/nginx/sites-enabled/
sudo nginx -t # Test configuration
sudo systemctl restart nginx
5. Secure with HTTPS
Use Let’s Encrypt for free SSL certificates:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d n8n.yourdomain.com
6. Run n8n as a Service
Create a systemd service to ensure n8n runs persistently:
sudo nano /etc/systemd/system/n8n.service
Add:
[Unit]
Description=n8n service
After=network.target
[Service]
Environment="DB_TYPE=postgresdb"
Environment="DB_POSTGRESDB_DATABASE=n8n"
Environment="DB_POSTGRESDB_USER=n8n_user"
Environment="DB_POSTGRESDB_PASSWORD=your_password"
Environment="DB_POSTGRESDB_HOST=localhost"
User=root
ExecStart=/usr/bin/n8n
Restart=always
[Install]
WantedBy=multi-user.target
Start the service:
sudo systemctl daemon-reload
sudo systemctl enable n8n
sudo systemctl start n8n
Verification
Access n8n at
https://n8n.yourdomain.com
.Check service status:
sudo systemctl status n8n
.Monitor logs:
journalctl -u n8n -f
.
Notes
Performance: For heavy workflows, allocate more RAM (≥2 GB) and CPU.
Backups: Regularly back up PostgreSQL/SQLite databases.
Updates: Keep Node.js and n8n updated for security patches.
For Docker-based installation, refer to Hostinger’s guide.
Subscribe to my newsletter
Read articles from Erik Chen directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
