OVHserver/opt/02-core/n8n-shared/docker-compose.yml
SamoilenkoVadym 610a45dc60 fix: настроен trust proxy для n8n за Traefik
Добавлена переменная N8N_PROXY_HOPS=1 для корректной работы
n8n за reverse proxy (Traefik). Это устраняет ValidationError
"The 'X-Forwarded-For' header is set but the Express 'trust proxy'
setting is false" при работе express-rate-limit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 18:33:27 +00:00

354 lines
10 KiB
YAML

version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n-shared
restart: unless-stopped
networks:
- traefik-public
- database-internal
- n8n-shared
env_file:
- .env
environment:
# General
N8N_HOST: n8n.ai-impress.com
N8N_PORT: 5678
N8N_PROTOCOL: https
WEBHOOK_URL: https://n8n.ai-impress.com/
# Database
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres-main
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n_shared
DB_POSTGRESDB_USER: n8n_user
DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
DB_POSTGRESDB_POOL_SIZE: 10
# Queue Mode (Redis)
QUEUE_BULL_REDIS_HOST: redis-main
QUEUE_BULL_REDIS_PORT: 6379
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
QUEUE_BULL_REDIS_DB: 2
EXECUTIONS_MODE: queue
# Workers configuration
QUEUE_HEALTH_CHECK_ACTIVE: 'true'
# Security
N8N_BASIC_AUTH_ACTIVE: 'false'
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
N8N_PAYLOAD_SIZE_MAX: 64
# Proxy configuration (for Traefik)
N8N_PROXY_HOPS: '1'
# Community Packages
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: 'true'
# Performance
EXECUTIONS_DATA_PRUNE: 'true'
EXECUTIONS_DATA_MAX_AGE: 168
N8N_CONCURRENCY_PRODUCTION_LIMIT: 5
# Timezone
GENERIC_TIMEZONE: Europe/London
TZ: Europe/London
volumes:
- n8n-data:/home/node/.n8n
- ./custom-nodes:/home/node/.n8n/custom
deploy:
resources:
limits:
cpus: '4'
memory: 2G
reservations:
cpus: '1'
memory: 512M
labels:
- "traefik.enable=true"
# Webhook роутер БЕЗ Authelia
- "traefik.http.routers.n8n-webhook.rule=Host(`n8n.ai-impress.com`) && (PathPrefix(`/webhook/`) || PathPrefix(`/webhook-test/`))"
- "traefik.http.routers.n8n-webhook.entrypoints=websecure"
- "traefik.http.routers.n8n-webhook.tls.certresolver=cloudflare"
- "traefik.http.routers.n8n-webhook.service=n8n-shared-service"
- "traefik.http.routers.n8n-webhook.priority=200"
# OAuth роутер БЕЗ Authelia
- "traefik.http.routers.n8n-oauth.rule=Host(`n8n.ai-impress.com`) && PathPrefix(`/rest/oauth`)"
- "traefik.http.routers.n8n-oauth.entrypoints=websecure"
- "traefik.http.routers.n8n-oauth.tls.certresolver=cloudflare"
- "traefik.http.routers.n8n-oauth.service=n8n-shared-service"
- "traefik.http.routers.n8n-oauth.priority=150"
# Основной роутер БЕЗ Authelia
- "traefik.http.routers.n8n-shared.rule=Host(`n8n.ai-impress.com`)"
- "traefik.http.routers.n8n-shared.entrypoints=websecure"
- "traefik.http.routers.n8n-shared.tls.certresolver=cloudflare"
- "traefik.http.routers.n8n-shared.service=n8n-shared-service"
- "traefik.http.routers.n8n-shared.priority=50"
- "traefik.http.routers.n8n-shared.middlewares=n8n-nocache"
# Middleware для отключения кэширования
- "traefik.http.middlewares.n8n-nocache.headers.customresponseheaders.Cache-Control=no-cache, no-store, must-revalidate"
- "traefik.http.middlewares.n8n-nocache.headers.customresponseheaders.Pragma=no-cache"
- "traefik.http.middlewares.n8n-nocache.headers.customresponseheaders.Expires=0"
# Сервис
- "traefik.http.services.n8n-shared-service.loadbalancer.server.port=5678"
# Worker 1 - High concurrency для быстрых задач
n8n-worker-1:
image: n8nio/n8n:latest
container_name: n8n-worker-1
restart: unless-stopped
command: worker
networks:
- database-internal
- n8n-shared
env_file:
- .env
environment:
# Database
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres-main
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n_shared
DB_POSTGRESDB_USER: n8n_user
DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
DB_POSTGRESDB_POOL_SIZE: 5
# Queue Mode (Redis)
QUEUE_BULL_REDIS_HOST: redis-main
QUEUE_BULL_REDIS_PORT: 6379
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
QUEUE_BULL_REDIS_DB: 2
EXECUTIONS_MODE: queue
# Worker settings
N8N_CONCURRENCY_PRODUCTION_LIMIT: 20
# Security
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
# Community Packages
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: 'true'
# Timezone
GENERIC_TIMEZONE: Europe/London
TZ: Europe/London
volumes:
- n8n-data:/home/node/.n8n
- ./custom-nodes:/home/node/.n8n/custom
deploy:
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '2'
memory: 1G
# Worker 2 - High concurrency
n8n-worker-2:
image: n8nio/n8n:latest
container_name: n8n-worker-2
restart: unless-stopped
command: worker
networks:
- database-internal
- n8n-shared
env_file:
- .env
environment:
# Database
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres-main
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n_shared
DB_POSTGRESDB_USER: n8n_user
DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
DB_POSTGRESDB_POOL_SIZE: 5
# Queue Mode (Redis)
QUEUE_BULL_REDIS_HOST: redis-main
QUEUE_BULL_REDIS_PORT: 6379
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
QUEUE_BULL_REDIS_DB: 2
EXECUTIONS_MODE: queue
# Worker settings
N8N_CONCURRENCY_PRODUCTION_LIMIT: 20
# Security
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
# Community Packages
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: 'true'
# Timezone
GENERIC_TIMEZONE: Europe/London
TZ: Europe/London
volumes:
- n8n-data:/home/node/.n8n
- ./custom-nodes:/home/node/.n8n/custom
deploy:
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '2'
memory: 1G
# Worker 3 - Medium concurrency для сложных задач
n8n-worker-3:
image: n8nio/n8n:latest
container_name: n8n-worker-3
restart: unless-stopped
command: worker
networks:
- database-internal
- n8n-shared
env_file:
- .env
environment:
# Database
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres-main
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n_shared
DB_POSTGRESDB_USER: n8n_user
DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
DB_POSTGRESDB_POOL_SIZE: 5
# Queue Mode (Redis)
QUEUE_BULL_REDIS_HOST: redis-main
QUEUE_BULL_REDIS_PORT: 6379
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
QUEUE_BULL_REDIS_DB: 2
EXECUTIONS_MODE: queue
# Worker settings
N8N_CONCURRENCY_PRODUCTION_LIMIT: 15
# Security
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
# Community Packages
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: 'true'
# Timezone
GENERIC_TIMEZONE: Europe/London
TZ: Europe/London
volumes:
- n8n-data:/home/node/.n8n
- ./custom-nodes:/home/node/.n8n/custom
deploy:
resources:
limits:
cpus: '3'
memory: 3G
reservations:
cpus: '1'
memory: 1G
# Worker 4 - Medium concurrency
n8n-worker-4:
image: n8nio/n8n:latest
container_name: n8n-worker-4
restart: unless-stopped
command: worker
networks:
- database-internal
- n8n-shared
env_file:
- .env
environment:
# Database
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres-main
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n_shared
DB_POSTGRESDB_USER: n8n_user
DB_POSTGRESDB_PASSWORD: ${DB_PASSWORD}
DB_POSTGRESDB_POOL_SIZE: 5
# Queue Mode (Redis)
QUEUE_BULL_REDIS_HOST: redis-main
QUEUE_BULL_REDIS_PORT: 6379
QUEUE_BULL_REDIS_PASSWORD: ${REDIS_PASSWORD}
QUEUE_BULL_REDIS_DB: 2
EXECUTIONS_MODE: queue
# Worker settings
N8N_CONCURRENCY_PRODUCTION_LIMIT: 15
# Security
N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
# Community Packages
N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: 'true'
# Timezone
GENERIC_TIMEZONE: Europe/London
TZ: Europe/London
volumes:
- n8n-data:/home/node/.n8n
- ./custom-nodes:/home/node/.n8n/custom
deploy:
resources:
limits:
cpus: '3'
memory: 3G
reservations:
cpus: '1'
memory: 1G
# Nginx для раздачи статических файлов
n8n-static:
image: nginx:alpine
container_name: n8n-static
restart: unless-stopped
networks:
- traefik-public
volumes:
- ./static:/usr/share/nginx/html:ro
labels:
- "traefik.enable=true"
# Роутер для главной страницы
- "traefik.http.routers.n8n-static-root.rule=Host(`n8n.ai-impress.com`) && (Path(`/`) || Path(`/index.html`))"
- "traefik.http.routers.n8n-static-root.entrypoints=websecure"
- "traefik.http.routers.n8n-static-root.tls.certresolver=cloudflare"
- "traefik.http.routers.n8n-static-root.service=n8n-static-service"
- "traefik.http.routers.n8n-static-root.priority=300"
# Роутер для статических файлов /assets/*, /static/*
- "traefik.http.routers.n8n-static.rule=Host(`n8n.ai-impress.com`) && (PathPrefix(`/assets/`) || PathPrefix(`/static/`) || Path(`/favicon.ico`) || PathRegexp(`^/.*\\.wasm$`))"
- "traefik.http.routers.n8n-static.entrypoints=websecure"
- "traefik.http.routers.n8n-static.tls.certresolver=cloudflare"
- "traefik.http.routers.n8n-static.service=n8n-static-service"
- "traefik.http.routers.n8n-static.priority=250"
# Сервис
- "traefik.http.services.n8n-static-service.loadbalancer.server.port=80"
volumes:
n8n-data:
networks:
traefik-public:
external: true
database-internal:
external: true
n8n-shared:
external: true