部署 - 使用 PM2

本文将会介绍如何配置 Nginx,将 Dify Chat 部署到生产环境。

生产构建

首先需要构建生产版本:

React SPA
Next.js
pnpm build

Nginx 配置

React SPA
Next.js
nginx.conf
# 注意:
# 将 dify-chat.com 替换为你的域名
# 将 /path/to/dify-chat/packages/react-app/dist/ 替换为你的构建产物路径
http {
    server {
        listen 443 ssl;
        server_name dify-chat.com;

        ssl_certificate     /etc/nginx/ssl/dify-chat.com_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/dify-chat.com.key;

        location /dify-chat/ {
            alias /path/to/dify-chat/packages/react-app/dist/;
            try_files $uri $uri/ /dify-chat/index.html;
        }
    }
}

启动 Next.js 项目

如果你使用的是 Next.js 版本,推荐使用 PM2 启动项目。

在 PM2 中配置:

ecosystem.config.js
module.exports = {
  apps: [
    {
      name: 'dify-chat-nextjs-app',
      cwd: '/path/to/dify-chat/packages/nextjs-app', // 工作目录
      script: 'pnpm',
      args: 'start', // 例如 nextjs 启动命令
      env: {
        NODE_ENV: 'production',
        PORT: 5300,
      },
    },
  ],
}

使用 PM2 启动项目:

pm2 start /path/to/ecosystem.config.js

Docker 部署