匠人学院 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. Dify 实战手册:用可视化拖拽搭建 AI 应用 — Dify 自部署完整指南:Docker Compose + Nginx 反向代理 + HTTPS
JR Academy · BlogCareer insights

Dify 实战手册:用可视化拖拽搭建 AI 应用 — Dify 自部署完整指南:Docker Compose + Nginx 反向代理 + HTTPS

从一台空白 VPS 到生产可用的 Dify 实例:Docker Compose 部署八个服务、Nginx 反向代理配置、Certbot 申请 SSL 证书、.env 关键参数解读,附常见坑排查

Published2026-12-01
Reading time3 min
Author

Contents

  • 前置条件
  • 架构速览
  • Step 1:拉代码,配 .env
  • 选择向量数据库
  • Step 2:启动 Dify 容器栈
  • Step 3:宿主机 Nginx 反向代理
  • Step 4:Certbot 申请 SSL 证书
  • 最终 Nginx 配置长这样
  • Step 5:Dify 首次初始化
  • 升级 Dify
  • 常见问题排查

云端托管的 Dify 够用,但数据出境、API 限流、每月 token 配额这几件事总会在不合时宜的时候让你难受。自部署一套就没这些烦恼——代价是要自己管机器、管证书、管升级。这章把整条路走一遍,顺带把坑标出来。

Dify self-hosting architecture overview

前置条件

机器规格:最低 2 vCPU / 4 GB RAM(跑完整栈 + 向量数据库),推荐 4 vCPU / 8 GB。磁盘留 40 GB 以上,向量数据会持续增长。

软件依赖:

  • Docker Engine 24.0+
  • Docker Compose v2(命令是 docker compose,不是旧版 docker-compose)
  • 一个指向该服务器 IP 的域名 A 记录(申请 SSL 证书用)

端口:服务器防火墙放开 80、443、22。不要直接暴露 Dify 内部端口(5001、3000 等)到公网。

架构速览

Dify 的 docker-compose.yaml 默认起八个服务:

服务 作用
api Dify 后端 Python Flask,端口 5001
web Next.js 前端,端口 3000
worker Celery 异步任务(RAG 索引、回调)
db PostgreSQL,应用元数据
redis 会话缓存 + 任务队列
weaviate 默认向量数据库
sandbox 代码执行沙箱(隔离环境运行用户代码)
nginx 内置反向代理,把 /api/ 路由到 api,其余路由到 web

外层再加一个宿主机 Nginx 做 HTTPS 终端,证书放在宿主机上,内部流量走 HTTP。

Step 1:拉代码,配 .env

git clone https://github.com/langgenius/dify.git
cd dify/docker
cp .env.example .env

.env.example 里有一百多个变量,大多数默认值可以直接用。必须改的几个:

# .env — 必改项

# 换成强随机字符串(openssl rand -hex 32 生成)
SECRET_KEY=your-random-secret-key-here

# 换成你的域名(后面配完 HTTPS 再改成 https://)
CONSOLE_URL=https://dify.example.com
APP_URL=https://dify.example.com

# 如果宿主机 80/443 已被占用,把内置 nginx 挪到别的端口
EXPOSE_NGINX_PORT=8080
EXPOSE_NGINX_SSL_PORT=8443

SECRET_KEY 不改的话用的是示例值,等于把签名密钥公开,任何人都能伪造 session。

选择向量数据库

默认是 Weaviate。如果你已经有 Qdrant 或 Milvus,在 .env 里改:

VECTOR_STORE=qdrant
QDRANT_URL=http://your-qdrant-host:6333
QDRANT_API_KEY=your-key

不改的话直接用内置 Weaviate 就行,零额外配置。

Step 2:启动 Dify 容器栈

cd dify/docker
docker compose up -d

第一次启动会拉镜像,根据网速大概要 3-8 分钟。确认所有服务跑起来:

docker compose ps

期望输出每个服务都是 Up(healthy 更好)。如果 api 或 worker 反复重启,先看日志:

docker compose logs api --tail 50
docker compose logs worker --tail 50

最常见原因:.env 的 SECRET_KEY 没改,或者 PostgreSQL 还没完成初始化就被 api 连接了——后者等十秒再 docker compose restart api 一般能解决。

Step 3:宿主机 Nginx 反向代理

内置 Nginx 监听 8080(或者你在 .env 里设的端口),宿主机 Nginx 在 80/443 做 TLS 终端,然后把流量转发进去。

先装 Nginx:

# Ubuntu/Debian
sudo apt install nginx -y

创建站点配置(先只配 HTTP,等会儿 Certbot 会自动改成 HTTPS):

# /etc/nginx/sites-available/dify
server {
    listen 80;
    server_name dify.example.com;

    # 大文件上传(知识库文档)
    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:8080;
        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;

        # WebSocket 支持(Dify 控制台用到)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 300s;
        proxy_connect_timeout 10s;
    }
}

启用并测试:

sudo ln -s /etc/nginx/sites-available/dify /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

此时用 curl http://dify.example.com 应该能拿到 Dify 前端的 HTML。

Step 4:Certbot 申请 SSL 证书

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d dify.example.com

Certbot 会自动修改你的 Nginx 配置,加上 ssl_certificate、ssl_certificate_key,并把 80 端口重定向到 443。完成后验证:

sudo nginx -t && sudo systemctl reload nginx
curl -I https://dify.example.com
# 期望看到 HTTP/2 200

证书 90 天到期,Certbot 的 systemd timer 会自动续期,不需要手动操作。

最终 Nginx 配置长这样

Certbot 改完之后,配置大概是:

server {
    listen 80;
    server_name dify.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name dify.example.com;

    ssl_certificate     /etc/letsencrypt/live/dify.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dify.example.com/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:8080;
        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_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 300s;
    }
}

注意 X-Forwarded-Proto https 硬编码成 https,不用 $scheme——因为宿主机到容器那段是 HTTP,如果用 $scheme 传进去的是 http,Dify 生成的链接会变成 http:// 开头,表单提交 CSRF 校验会报错。

Step 5:Dify 首次初始化

打开浏览器访问 https://dify.example.com,进入管理员账号创建页面。填完邮箱和密码,登进控制台,去「设置 → 模型供应商」填你的 OpenAI / Anthropic / 本地 Ollama 的 API Key。

如果你用 Ollama 或 LiteLLM 这类本地模型,BASE_URL 要填宿主机内网 IP 而不是 localhost,容器里的 localhost 解析不到宿主机。Docker Compose 默认网络下,用 host.docker.internal(Mac/Windows)或宿主机内网 IP(Linux)。

升级 Dify

cd dify/docker
git pull
docker compose pull
docker compose down
docker compose up -d

数据卷(PostgreSQL、Weaviate、上传文件)挂在命名 volume 上,down 不会删数据。但升级前建议先备份 PostgreSQL:

docker compose exec db pg_dump -U postgres dify > dify-backup-$(date +%Y%m%d).sql

常见问题排查

问:首页白屏,控制台报 502 先看 docker compose ps,确认 api 和 web 都在跑。再检查宿主机 Nginx 的 proxy_pass 端口有没有对上 .env 里的 EXPOSE_NGINX_PORT。

问:上传知识库文档报 413 Request Entity Too Large Nginx 默认限制 1MB。在宿主机 Nginx 配置里加 client_max_body_size 100M;(已在上面的示例里包含)。

问:certbot 报 "Could not bind to IPv4 or IPv6" certbot --nginx 的 standalone 模式需要占用 80 端口,但你的 Nginx 已经在用。用 --nginx 插件就好(不是 --standalone),它会和 Nginx 协作,不需要停服。

问:Dify 生成的链接是 http:// 不是 https:// .env 里的 CONSOLE_URL 和 APP_URL 还没改成 https://。改完 docker compose restart api 生效。

问:磁盘快满了 向量数据、Docker 镜像层和日志是三大占用。清理未使用镜像:docker image prune -f。Weaviate 数据在 volumes/weaviate,没有简单缩容方法,规划时提前留够空间。


自部署的核心优势是数据完全在自己手里,模型调用也走自己的 API Key,适合有数据合规要求或者用量大的场景。跑起来之后日常维护很少,主要就是偶尔升级版本和看一眼磁盘使用率。

Author
Share or copy the link
← Previous articleDify 实战手册:用可视化拖拽搭建 AI 应用 — Dify RAG 知识库实战:分块策略、检索调优与 rerankingNext article →Coze 实战手册:零代码搭建 AI Bot,从聊天机器人到自动化工作流 — Coze 是什么:字节跳动出品的 AI Bot 开发平台,零代码也能搞定

Related articles

USYD 医疗初创盘点、网络平台注意义务法案、全身 MRI 广告研究

2026-12-02

UQ 皮肤癌在线硕士开办 20 周年、中澳绿色钢铁对话、HIV 预防提醒

2026-12-02

UNSW iFire 2.3 火场模拟系统、AI 卵巢癌预后研究、艺术家与 AI 版权调查

2026-12-02

ANS-C01 退役倒计时 29 天 · AIB-C01 Beta $50 新认证上线 · MLA-C02 Beta 报名开放

2026-12-02

Amazon开放首个自研大模型Ergo,代理作弊率实测差距悬殊,Anthropic格密码结果暂无现实威胁

2026-12-02

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

2026-12-01
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.