匠人学院 JR Academy
  • Position

    Where am I now, and where should I go?

    How your job is changing, where your experience can take you and what you still need for a target role, worked out from what you have actually done. Free, and the full result needs no sign-up.

    Analyse my career and skills

    Look up a career

    Will AI replace my job?AI impact and transition paths for common careersNew jobs in the AI eraWhat they do, what they need, how to move in

    Focused tools

    AI Engineer interview readiness30 timed questions on what you still need before interviewsCareer personality testDirections that suit how you workReturning to China checkJob prospects in China by school, major and graduation date

    AI coach

    Talk to your AI coachStill unsure after your result? Talk through what is holding you back
  • Core courses

    AI Engineer BootcampEngineering bootcamp from LLM apps to agentsAI Engineer Full-Stack Project Class16 weeks · RAG and full-stack AI projectsVibe Coding Masterclass8 weeks · direct agents to build and ship a productAI Essentials10 hours · use AI for email, reports, data and copyAI Office Automation Course8 weeks · help a whole company adopt AIOne-Person Company (OPC) Bootcamp15 weeks in person · build a one-person company with AIAll courses →

    AI engineering

    Machine Learning & Data Engineering Full-Stack ClassAI Agent & MCP Project BootcampAI Engineer Core TechniquesAI Engineer FoundationsAI Engineer Advanced: RAG to Agents and TuningClaude Code TasterAll AI engineering courses →

    AI at work

    AI Coding for everyoneClaude Code One-Day Masterclass (Non-Technical)Enterprise AI Automation BootcampAI Marketing BootcampAI Risk, Governance and Audit CourseOpenClaw 4-Week Personal AI Assistant BootcampAll AI-at-work courses →

    Career development

    AI Product Manager (BA) Bootcamp + InternshipAustralia IT Interview BootcampAustralia IT Technical Interview BootcampAustralia IT Resume BootcampAustralia Big Tech Job Search BootcampAustralia IT Career Planning BootcampAll career courses →

    Learn free first

    Vibe CodingAI for office workPrompt MasterAI EngineerAI data analysisResource centerInstructorsAll learning paths →
  • Evidence

    What will convince an employer?

    Certifications, projects, team work and competition entries, collected into one portfolio.

    See the portfolio

    Certifications

    Cert Master · all certificationsPrep and mock exams for AWS, Azure, GCP, Claude and moreAWS CLF-C02Entry-level AWS cloud certificationAWS SAA-C03Entry certification for cloud architectsClaude certificationsAnthropic Claude certification seriesAll certifications →

    Projects and team work

    P3 team projectsBuild a project with real teammates in a simulated team workflowP3 project experienceThe parts of a P3 project that go on your resumeDemo DayProject showcaseP3 certificatesProof once a project is completeAll of P3 →

    Competitions and work

    HackathonsBuild something against the clockSubmit your workAdd your project to the showcaseCareerOS portfolioDo tasks in the desktop app; your results become portfolio pieces
    Cert MasterBrowser extension, app and mini programScreenshot a question for analysis and practise anywhereAbout Cert Master
  • Connect

    How do I get myself in front of employers?

    Resume, interviews, referrals and mentors. See how far you are from the target role first, then decide what to fix.

    Start with Jobpin

    Resume and openings

    Graduate careersGraduate preparation across Australia, China, Malaysia, Singapore, the US and UKJobpinAI job search workspace: resume, roles, applicationsAI resumeRewrite your resume against a job descriptionReferralsRoles shared by students and mentorsOpportunitiesInternships, projects and collaborationsOffer boardOffers students have received

    Interviews

    AI Engineer interview guideSeven areas, with worked examplesFDE interview guideFive rounds, from scoping to the customer roundAI mock interviewPractise by text or voice and see the gapsInterview storiesReal interview experiencesSystem Design handbookPrepare for system design interviewsAll interview prep →

    Mentors

    1:1 mentorsBook AI, career and technical mentors by the hourGroup tutoringShare a tutor with a few others and pay less eachCareer coachingResume, interview and direction packages
    Jobpin desktopOne workspace for the whole job searchOrganise real experience and refine resume versions for target roles on macOS or Windows.About Jobpin
BusinessMembershipDownload CareerOS
0
匠人学院 JR Academy

Follow Us

linkedinfacebooktwitterinstagramyoutube

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png
Airbotix · AI learning & creation for kids Another Life · AI story game
Products46

CareerOS and tools

  • CareerOS
  • Cert Master
  • Jobpin
  • Jobpin web
  • Jobpin report
  • Jobpin desktop download
  • My job search reports
  • Buy report credits
  • Jobpin billing
  • AI Toolbox
  • AI Skill Marketplace

Membership

  • Membership
  • AI membership

Courses

  • Bootcamps
  • Training Camp
  • Kanban learning
  • AI Builder course
  • MCP course
  • NotebookLM workshop
  • Business Analyst course
  • Web Full-Stack Bootcamp
  • DevOps Bootcamp
  • Data Engineering Bootcamp
  • Data Analysis Bootcamp
  • Coding for Beginners
  • Algorithm Bootcamp

Career services

  • Graduate careers
  • Graduate careers in Australia
  • Graduate careers in China
  • Graduate careers in Malaysia
  • Graduate careers in Singapore
  • Graduate careers in the US
  • Graduate careers in the UK
  • 1:1 coaching
  • Career coaching
  • AI Engineer VIP
  • BA & PM Internship
  • Data Science Internship
  • Data Analysis Internship
  • Marketing Internship
  • Resume Review
  • Interview Coaching
  • Job Application Service
  • Job Monitoring
  • LinkedIn Management
  • LinkedIn Networking
Library57

Learning paths

  • All Learning Paths
  • AI Engineer
  • Context Engineering
  • Vibe Coding
  • Prompt Master
  • AI Builder
  • AI Product Manager
  • Python Basics
  • AI Productivity
  • AI Data Analysis
  • AI Finance
  • AI Content Creation
  • AI Image Creation
  • Frontend Development
  • Hermes Agent
  • OpenClaw Local Agent

Interactive labs

  • Prompt Lab
  • Frontend Lab
  • JavaScript Lab
  • Python Lab
  • AWS Lab
  • Azure Lab
  • LLM Lab
  • Git Lab

Reference and guides

  • Resources
  • Wiki
  • Cheat sheets
  • Roadmaps
  • AI roadmaps
  • Videos
  • Ebooks
  • Blog
  • Interview handbook
  • Mock exams
  • Free resources

Cities

  • Sydney
  • Melbourne
  • Brisbane
  • Adelaide
  • Singapore
  • Kuala Lumpur
  • London
  • New York
  • San Francisco
  • Los Angeles
  • Seattle
  • Toronto
  • Vancouver

Immigration

  • Australia Immigration
  • Skilled Visa 189/190/491
  • Employer Sponsored 482/186/494
  • Business Visa 188/888
  • UK Immigration
  • US Immigration
  • Canada Immigration
  • Singapore immigration
  • Malaysia immigration
Business20

For business

  • AI for Business
  • Business portal sign-in
  • Corporate Training
  • Internship Partnership
  • Recruitment Partnership
  • Enterprise (EN)

Metatree AI Lab

  • Metatree AI Lab (Chinese)
  • AI solutions (Chinese)
  • Digital employees (Chinese)
  • Case studies (Chinese)
  • Metatree AI Lab
  • AI services
  • Digital employees
  • Case studies

AI education for kids

  • Airbotix — AI Learning & Creation for Kids
  • AU Family Resource Hub
  • NAPLAN Report Guide
  • My School Data Guide
  • Sydney Private School Fees 2026
  • Kids Coding Programs
About15

Company

  • About Us
  • Our Mentors
  • Become a Mentor
  • Metaverse Classroom
  • JR Careers
  • Another Life — AI Story Game
  • Contact Us

Help and policies

  • FAQs
  • Terms & Conditions
  • Privacy Policy
  • Cancellation & Refund Policy
  • Site map

Friend links

  • CS Browser

Contact

  • hello@jiangren.com.au
  • 0421-672-555

Offices

Level 10b, 144 Edward Street, Brisbane CBD (Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
45A13, Block B, Oriental Hope Tianxiang Plaza, 500 Tianfu Avenue Middle Section, Wuhou District, Chengdu, Sichuan, China
Business Hub, 155 Waymouth St, Adelaide SA 5000
Disclaimer
footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

All content on the JR Academy website, including course materials, logos, and information provided, is protected under Australian intellectual property laws. Unauthorized use, sale, distribution, reproduction, or modification is strictly prohibited. Violations may result in legal action. By accessing our website, you agree to respect our intellectual property. JR Academy Pty Ltd reserves all rights, including patents, trademarks, and copyrights. Any infringement will be subject to legal prosecution. View Terms of Service

© 2017-2026 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572

HomeLearnCoursesCerts
  1. Home
  2. Learn
  3. Blog
  4. n8n 自动化工作流实战指南 — n8n 自托管部署完全指南:从零到生产环境
JR Academy · BlogCareer insights

n8n 自动化工作流实战指南 — n8n 自托管部署完全指南:从零到生产环境

Docker Compose + PostgreSQL 标准配置、Nginx HTTPS、Cloudflare Tunnel、备份策略、常见踩坑——一篇搞定生产级自托管

Published2026-11-30
Reading time2 min
Author

Contents

  • 选服务器:先别省钱
  • 标准部署方案:Docker Compose + PostgreSQL
  • 目录结构
  • docker-compose.yml
  • .env 文件
  • HTTPS 方案一:Nginx + Let's Encrypt
  • 安装 Certbot
  • Nginx 配置 /etc/nginx/sites-available/n8n
  • HTTPS 方案二:Cloudflare Tunnel(推荐,零开端口)
  • 步骤
  • 备份:最容易被忽视,最不能出错
  • 版本升级:不要每次都升 latest
  • 最常见的 7 个踩坑
  • 成本速算

自托管的最大价值是:数据不出你的服务器,执行次数无上限,成本随量封顶。但 60% 的人在上线前 30 天就因为配置失误或缺少备份而遭遇故障。这章把正确姿势一次说清。

n8n 自托管架构


选服务器:先别省钱

场景 RAM CPU 存储
测试 / 个人项目 2 GB 1 vCPU 20 GB SSD
小团队生产(<50 workflow) 4 GB 2 vCPU 40 GB SSD
中型团队(50–200 workflow) 8 GB 4 vCPU 80 GB SSD

存储必须用 SSD——n8n 每次执行都会写日志,HDD 的随机写入速度会让 workflow 队列积压。RAM 不够会让 Node.js 进程在执行高并发 workflow 时直接 crash。

推荐供应商:Hetzner(性价比最高,欧洲数据中心)、DigitalOcean(文档友好)、Vultr(中国大陆网络相对快)。


标准部署方案:Docker Compose + PostgreSQL

这是官方推荐的生产配置。SQLite 仅适合本地测试,生产环境必须换 PostgreSQL。

目录结构

/opt/n8n/
├── docker-compose.yml
├── .env
└── local-files/        # workflow 读写本地文件的共享目录

docker-compose.yml

version: "3.8"

services:
  postgres:
    image: postgres:16-alpine
    restart: always
    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: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"    # 只绑定本机,不直接暴露到公网
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: ${POSTGRES_DB}
      DB_POSTGRESDB_USER: ${POSTGRES_USER}
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_HOST: ${N8N_HOST}
      N8N_PORT: 5678
      N8N_PROTOCOL: https
      WEBHOOK_URL: https://${N8N_HOST}/
      GENERIC_TIMEZONE: Australia/Sydney
      EXECUTIONS_DATA_PRUNE: "true"
      EXECUTIONS_DATA_MAX_AGE: 168         # 保留7天执行历史(小时)
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:
  n8n_data:

关键细节:ports 写 127.0.0.1:5678:5678 而非 5678:5678,这样 n8n 只监听本机回环,不直接暴露在公网——只有 Nginx 反向代理才能访问它。

.env 文件

POSTGRES_USER=n8n
POSTGRES_PASSWORD=换成强随机密码_至少20位
POSTGRES_DB=n8n

N8N_ENCRYPTION_KEY=换成随机字符串_至少32位_丢失则凭证全废
N8N_HOST=n8n.your-domain.com

启动:

cd /opt/n8n
docker compose up -d

# 查看日志确认启动成功
docker compose logs n8n --tail=50 -f

HTTPS 方案一:Nginx + Let's Encrypt

适合有固定公网 IP 的 VPS,80/443 端口可以对外开放。

安装 Certbot

apt install -y nginx certbot python3-certbot-nginx

# 申请证书(替换域名)
certbot --nginx -d n8n.your-domain.com

Nginx 配置 /etc/nginx/sites-available/n8n

server {
    listen 80;
    server_name n8n.your-domain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name n8n.your-domain.com;

    ssl_certificate /etc/letsencrypt/live/n8n.your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/n8n.your-domain.com/privkey.pem;

    # WebSocket 支持(n8n 实时推送需要)
    location / {
        proxy_pass http://127.0.0.1:5678;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 https;
        proxy_read_timeout 300s;     # webhook 长轮询需要较大超时
        client_max_body_size 50M;    # 允许上传文件
    }
}
ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

HTTPS 方案二:Cloudflare Tunnel(推荐,零开端口)

不需要固定 IP,不需要开放防火墙端口,安全性更好。适合家庭宽带或有 NAT 的环境。

步骤

  1. 在 Cloudflare 后台创建 Tunnel,下载 cloudflared 凭证文件(JSON)
  2. 在 docker-compose.yml 里加一个 cloudflared 服务:
  cloudflared:
    image: cloudflare/cloudflared:latest
    restart: unless-stopped
    command: tunnel --no-autoupdate run
    environment:
      TUNNEL_TOKEN: ${CLOUDFLARE_TUNNEL_TOKEN}
    depends_on:
      - n8n
  1. 在 .env 里加 CLOUDFLARE_TUNNEL_TOKEN=你的token
  2. 在 Cloudflare 后台把 Tunnel 路由到 http://n8n:5678(容器内部网络名)

完成后公网用 https://n8n.your-domain.com 访问,流量全程走 Cloudflare Edge,服务器无需开任何入站端口。


备份:最容易被忽视,最不能出错

# 备份脚本 /opt/n8n/backup.sh
#!/bin/bash
set -euo pipefail

DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR=/opt/n8n/backups

mkdir -p "$BACKUP_DIR"

# 备份 PostgreSQL
docker exec n8n-postgres-1 \
  pg_dump -U n8n n8n | gzip > "$BACKUP_DIR/db_$DATE.sql.gz"

# 备份 .n8n 目录(包含凭证加密数据)
docker run --rm \
  -v n8n_n8n_data:/data \
  -v "$BACKUP_DIR":/backup \
  alpine tar czf "/backup/n8n_data_$DATE.tar.gz" /data

# 只保留最近 7 天
find "$BACKUP_DIR" -name "*.gz" -mtime +7 -delete

echo "备份完成: $DATE"

加入 crontab(每天凌晨3点执行):

chmod +x /opt/n8n/backup.sh
crontab -e
# 加入:
# 0 3 * * * /opt/n8n/backup.sh >> /var/log/n8n-backup.log 2>&1

备份同时要异地存储:用 rclone 把备份文件同步到对象存储(如 Cloudflare R2、AWS S3、阿里云 OSS)。


版本升级:不要每次都升 latest

# 1. 先查看当前版本
docker exec n8n-n8n-1 n8n --version

# 2. 升级前备份
/opt/n8n/backup.sh

# 3. 拉新镜像并重启
docker compose pull n8n
docker compose up -d n8n

# 4. 查看日志确认正常
docker compose logs n8n --tail=20 -f

建议策略:锁定小版本(如 image: docker.n8n.io/n8nio/n8n:1.85),每月人工评估一次是否升级,安全补丁版本立即跟进。


最常见的 7 个踩坑

坑 症状 解法
N8N_ENCRYPTION_KEY 没设或丢了 凭证全部无法解密,需要重新配所有 API Key 首次启动前设好,妥善保存到密码管理器
SQLite 用于生产 并发执行时数据丢失 换 PostgreSQL
5678 端口直接暴露公网 不需要登录就能访问 n8n 用 Nginx/Cloudflare Tunnel 做反向代理
忘记配置 WEBHOOK_URL Webhook 节点生成错误的回调地址 设 WEBHOOK_URL=https://你的域名/
服务器时区错误 Cron 触发器时间不准 设 GENERIC_TIMEZONE=Asia/Shanghai(或对应时区)
磁盘被执行日志撑满 n8n 突然停止运行 开启 EXECUTIONS_DATA_PRUNE=true
没有备份 服务器故障后数据全丢 按上面的备份脚本每天自动备份

成本速算

自托管的盈亏点大约在 每月 20,000 次执行:

  • Hetzner CX22(4GB/2vCPU):约 €4/月
  • n8n Cloud Pro(10,000次执行):€60/月
  • n8n Cloud Business(40,000次执行):€800/月

执行量大的团队用自托管节省的费用,一年可以买下好几台服务器。

Author
Share or copy the link
← Previous articlen8n 自动化工作流实战指南 — n8n 核心体系:Trigger、Node、Expression 全解Next article →n8n 自动化工作流实战指南 — n8n AI Agent 深度实战:Claude + 记忆 + 工具 + RAG 知识库

Related articles

🇦🇺测一下:袋鼠国码农能当FDE吗?

2026-12-01

Monash 研究:肠道酸度是膳食纤维降血压的关键;AI 搬运新闻冲击维州选举信息;MPAC 公布 2027 演出季

2026-12-01

Adelaide 物理学家获 $250,000 总理科学奖;全球葡萄酒消费六十年降四分之一;残障师范生实习障碍研究

2026-12-01

DVA-C03今日上线首发 · Google Cloud AI Agent认证完整解析 · AZ-401本月GA替代AZ-400

2026-12-01

Anthropic推迟下一代模型并调百人做安全,AWS推出AI办公三件套,Google让用户单独关掉AI训练

2026-12-01

GitHub Copilot 实战指南 — Copilot AI Code Review:30 秒让 AI 帮你审 PR,三档深度随需切换

2026-11-30
View all articles →

Done reading? Next steps

Not sure what to learn next? Tell us where you are

Tell us what you do now and where you want to go. See your gaps in skills, evidence, experience, expression and positioning, and what to work on first. No sign-in needed.

Compare with my situation
  • SkillAI Engineer Bootcamp13 weeks, 12 Theory + 13 Practice live classes. You build one Agent system across Context, RAG, Tools, Memory and production Evals. Built for Applied AI and Agent Engineer roles.See the program →
  • PositioningLearning roadmaps by roleFrontend, backend, data, AI and more, laid out stage by stage in the order to learn them.All roadmaps →
  • ExpressionTry an AI mock interviewPick a role and run a mock interview to practise explaining your experience and projects.Practise now →

Not sure what to do next?

Take this page's topic with you and see where your gaps are.

Compare with my situation
JR Academy
AI learning for the global Chinese community
BootcampsFree resourcesLearn AICareer coaching
精选推荐
AI Career Impact Map
Assess career exposure and explore transition paths and learning options
Popular tool
AI & Data Bootcamps
Build your skills through structured courses and hands-on projects
Popular courses
1:1 Career Coaching
Work with an experienced mentor on your resume and interview preparation
Career coaching
Custom Corporate Training
AI training tailored to your team
Business services
Popular tags
Vibe CodingAI codingCursorClaudeJob searchPromptFrontend developmentBackend development
Subscribe to updates

Receive AI learning resources, technical tutorials and career advice by email.

We respect your privacy and do not send spam.