n8n Installation: Self-Hosted Automation with Docker and Nginx on Ubuntu
In this guide, you will learn how to run n8n securely on your own server.
We will do a production-ready installation with Docker, PostgreSQL, Nginx and HTTPS.
What Will You Learn in This Guide?
- Installing n8n on Ubuntu with Docker Compose
- Persistent data storage using PostgreSQL
- Providing secure access via HTTPS with Nginx
- Creating and testing the first workflow
What is n8n and Why is it Used?
n8n is an open source workflow automation platform.
It allows you to link services together with a visual editor.
Unlike SaaS tools, it runs on your own infrastructure.
This way you get data privacy and full control.
Installation Prerequisites
Before you start, you should have the following ready:
- Ubuntu 22.04 or newer server
- A domain name pointed to the server
- User with authority
sudo - Docker and Docker Compose
For Docker installation:
sudo apt update
sudo apt install docker.io docker-compose -y
- This command installs Docker and Docker Compose.
1. Creating the Docker Compose Configuration
- Create a folder for n8n services:
mkdir ~/n8n && cd ~/n8n
nano docker-compose.yml
- This command creates the project directory and opens the configuration file.
Add the following configuration:
version: "3.7"
services:
db:
image: postgres:14
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: n8npass
POSTGRES_DB: n8n
volumes:
- postgres_data:/var/lib/postgresql/data
n8n:
image: n8nio/n8n
ports:
- "5678:5678"
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: db
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: n8npass
N8N_BASIC_AUTH_ACTIVE: "true"
N8N_BASIC_AUTH_USER: admin
N8N_BASIC_AUTH_PASSWORD: strongpass
N8N_HOST: n8n.ornek.com
WEBHOOK_TUNNEL_URL: https://n8n.ornek.com
depends_on:
- db
volumes:
- n8n_data:/home/node/.n8n
volumes:
postgres_data:
n8n_data:
- This structure runs PostgreSQL and n8n services together.
2. Starting the n8n Service
- Run containers in the background:
docker-compose up -d
- This command starts n8n and PostgreSQL services.
For access from browser:
http://sunucu_ip:5678
- If HTTPS is not available, the browser may give a warning.
3. Security with Nginx and HTTPS
- HTTPS is mandatory in the production environment.
Nginx and Certbot Installation
sudo apt install nginx certbot python3-certbot-nginx -y
- This command installs Nginx and Let's Encrypt tools.
Nginx Reverse Proxy Setting
server {
listen 80;
server_name n8n.ornek.com;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- This structure puts Nginx in front of n8n as a reverse proxy.
Activate:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Obtaining an SSL Certificate
sudo certbot --nginx -d n8n.ornek.com
- This command retrieves the HTTPS certificate and automatically identifies it.
4. Creating the First n8n Workflow
- After logging into the interface:
-
Create New Workflow
-
Add webhook trigger
-
HTTP Method: POST
- Path: test-webhook
-Add a Set node next to it. Type "Hello from n8n!" as the value.
For testing:
curl -X POST https://n8n.ornek.com/webhook/test-webhook
- This command triggers the workflow.
Sample Usage Scenario
- With n8n the following can be done automatically:
-
Server monitoring with UptimeRobot
-
Automatic restart when the service crashes
-
Slack and WhatsApp notifications
-
Cloudflare DNS or SSL update
-
In this way, manual intervention is reduced.
Frequently Asked Questions (FAQ)
1. Why should n8n be installed with Docker? Installation, updating and backup become easier.
2. Why PostgreSQL instead of SQLite? More stable and scalable in production.
3. Does it work without HTTPS? It works, but it's not secure.
4. Do Workflows run in parallel? Yes, they run simultaneously if there are enough resources.
5. How to backup? Back up Docker volumes regularly.
Result
You have installed n8n securely and scalably on Ubuntu. You can now manage automation processes in your own infrastructure.
You can try GenixNode infrastructure now for high performance and secure servers 🚀

