马来西亚云服务

node --version npm --version

Step 2: Install n8n Globally

Run the following command to install n8n as a global npm package:

Bash
npm install -g n8n

This will download and install n8n along with all required dependencies.

Step 3: Start n8n

Once installed, start n8n with:

Bash
n8n start

n8n will initialize and display startup logs. By default, it listens on port 5678.

Step 4: Access the Dashboard

Open your browser and navigate to: http://localhost:5678.

n8n dashboard

You’ll be greeted by the n8n setup wizard, where you can create your first owner account.

💡 Note: Data is stored in SQLite by default (~/.n8n directory). This is fine for testing, but not recommended for production.

5. Installation — Method B: Using Docker

Docker provides a clean, isolated environment for running n8n. Make sure Docker is installed on your system before proceeding.

Step 1: Pull the Official n8n Image

Bash
docker pull n8nio/n8n

Step 2: Run the Container

Run n8n with a mounted volume for persistent data:

Bash

docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n

Breaking this down:

Step 3: Verify It’s Running

Check that the container is active:

Bash
docker ps

You should see the n8n container listed. Open http://localhost:5678 to access the UI.

6. Installation — Method C: Docker Compose (Recommended)

Docker Compose is the most robust way to self-host n8n. It allows you to define your entire setup in a single YAML file, making it easy to replicate, update, and manage.

Step 1: Create the docker-compose.yml File

Create a new directory for your n8n setup and add a docker-compose.yml file:

yaml
mkdir n8n-setup && cd n8n-setup
nano docker-compose.yml

Paste the following configuration:

yaml

version: '3.8'
services:
  n8n:
    image: n8nio/n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=your-domain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://your-domain.com/
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=your_password
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - postgres

  postgres:
    image: postgres:15
    restart: unless-stopped
    environment:
    - POSTGRES_DB=n8n
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=your_password
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  n8n_data:
  postgres_data:

Step 2: Start All Services

Bash
docker compose up -d

The -d flag runs the services in detached (background) mode. Docker will pull the necessary images and start both n8n and PostgreSQL.

Step 3: Verify

Bash
docker compose ps

Both the n8n and PostgreSQL services should be running.

7. Configuring n8n for Production

Running n8n on a public server requires a few additional steps to make it secure and accessible.

A. Setting Up a Reverse Proxy with Nginx

A reverse proxy sits in front of n8n and handles HTTPS. Here’s a basic Nginx server block:

JavaScript
server {
    server_name your-domain.com;
    locations / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

B. Enabling HTTPS with Let’s Encrypt

Install Certbot and obtain a free SSL certificate:

Bash
sudo apt install certbot python3-certbot-nginx

sudo certbot --nginx -d your-domain.com

Certbot will automatically configure HTTPS in your Nginx config and set up auto-renewal.

C. Key Environment Variables

8. Connecting to a Database

By default, n8n uses SQLite, which is fine for local testing but not suitable for production use. SQLite doesn’t handle concurrent access well, and backups are trickier.

A. Why PostgreSQL?

B. Configuring n8n to Use PostgreSQL

Add these environment variables to your n8n service:

Bash

DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=your_secure_password

C. Running Migrations

n8n automatically runs database migrations on startup. No manual SQL scripts are required — simply start n8n and it will create all necessary tables.

9. Setting Up Your First Workflow

Now that n8n is running, let’s build a simple workflow to see how everything fits together.

Step 1: Navigate to the Workflow Editor

Log in to your n8n instance and click the ‘+ New Workflow‘ button in the top-right corner.

Step 2: Add a Trigger Node

Every workflow starts with a trigger. Click the ‘+‘ button to open the node panel and search for one of these popular triggers:

Step 3: Connect Action Nodes

Add action nodes to perform tasks. For example:

Drag a line from the output of your trigger to the input of the action node to connect them.

Step 4: Test and Activate

Click ‘Execute Workflow’ to test your workflow manually. Once you’re satisfied, toggle the Active switch in the top-right to enable it. n8n will now run the workflow automatically based on your trigger conditions.

10. Keeping n8n Running (Process Management)

For n8n to serve you reliably, it needs to stay running even after crashes or server reboots.

A. For npm Installs: Using PM2

Bash

npm install -g pm2
pm2 start n8n
pm2 save
pm2 startup

PM2 will automatically restart n8n if it crashes and launch it on server boot.

B. For Docker: Restart Policy

In your docker-compose.yml or Docker run command, set the restart policy:

Bash
restart: unless-stopped

This ensures n8n restarts automatically after crashes or reboots (unless you manually stop it).

C. For systemd (Linux Servers)

Create a systemd service file at /etc/systemd/system/n8n.service to manage n8n as a system service. Use systemctl enable n8n and systemctl start n8n to activate it.

11. Conclusion

Congratulations! You now have a fully self-hosted n8n instance up and running. Let’s recap what you’ve accomplished:

A. What’s Next?

Now that the foundation is in place, here’s what you can explore:

Kaif

Share
Published by
Kaif
3 weeks ago

Recent Posts

Is WordPress 6.9 a Game Changer? Here’s a Look

1. Introduction WordPress 6.9, codenamed "Gene," is the final major release of 2025 and one…

7 days ago

Docker vs Kubernetes: Containerization Showdown

1. Introduction to Containerization 1.1 What Is Containerization and Why It Matters Modern software development…

1 week ago

Top Survival Games Perfect for Dedicated Server Hosting

Introduction Survival games have become one of the most enduring and beloved genres in modern…

1 month ago

Containerize and Deploy Node.js Applications With VPS Malaysia

1. What is Node.js? Node.js lets you use JavaScript to build the "brain" of a…

1 month ago

NVMe vs M.2: What’s the Difference and Which One Do You Need?

1. Introduction If you have ever shopped for a new SSD or tried to upgrade…

1 month ago