8. 🤖 n8n (Tự động hóa)

8.1. Tạo thư mục và cấu hình

bash

mkdir -p ~/n8n && cd ~/n8n

8.2. Tạo file .env

env

POSTGRES_USER=n8n
POSTGRES_PASSWORD=Your_Password
POSTGRES_DB=n8n

8.3. Tạo file docker-compose.yml

yaml

version: '3.8'

services:
  postgres:
    image: postgres:15
    container_name: n8n_postgres
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - n8n_network

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n_app
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_USER=${POSTGRES_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - N8N_HOST=n8n.huancoc.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.huancoc.com/
      - GENERIC_TIMEZONE=Asia/Ho_Chi_Minh
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - n8n_network

volumes:
  postgres_data:
  n8n_data:

networks:
  n8n_network:
    driver: bridge

8.4. Khởi chạy

bash

docker compose up -d

8.5. Cấu hình trên Nginx Proxy Manager

  • Domain: n8n.huancoc.com
  • Scheme: http
  • Forward IP: 192.168.3.5
  • Forward Port: 5678
  • SSL: Request Let’s Encrypt và bật Force SSL

By huannv

Leave a Reply

Your email address will not be published. Required fields are marked *