部署
🌐 Deployment
Page summary:
部署选项包括硬件/软件先决条件、环境变量设置以及在启动前构建管理面板。在文档中:提供了针对特定提供商的指南和高级指南的链接,以帮助选择合适的托管策略。
Strapi 为你的项目或应用提供了多种部署选项。你的 Strapi 应用可以部署在传统托管服务器上,或你偏好的托管提供商上。
🌐 Strapi provides many deployment options for your project or application. Your Strapi applications can be deployed on traditional hosting servers or your preferred hosting provider.
以下文档介绍了如何使用几个常见的托管选项准备 Strapi 以进行部署的基础知识。
🌐 The following documentation covers the basics of how to prepare Strapi for deployment on with several common hosting options.
你可以使用 Strapi Cloud 快速部署和托管你的项目。
🌐 You can use Strapi Cloud to quickly deploy and host your project.
如果你已经使用内容类型构建器创建了内容结构,并通过内容管理器向本地(开发)Strapi 实例添加了一些数据,你可以利用数据管理系统将数据从一个 Strapi 实例传输到另一个实例。
🌐 If you already created a content structure with the Content-Type Builder and added some data through the Content Manager to your local (development) Strapi instance, you can leverage the data management system to transfer data from a Strapi instance to another one.
另一种可能的工作流程是首先在本地创建内容结构,将项目推送到基于 git 的存储库,将更改部署到生产环境,然后再将内容添加到生产实例。
🌐 Another possible workflow is to first create the content structure locally, push your project to a git-based repository, deploy the changes to production, and only then add content to the production instance.
对于自托管的 Kubernetes 部署,我们建议使用 npm 而不是 pnpm。pnpm 对依赖的激进提升可能会破坏本地模块,例如 mysql2——你的应用可能依赖它们。npm 更平坦、更可预测的 node_modules 布局有助于确保本地包正确加载。
🌐 For self-hosted Kubernetes deployments, we recommend using npm rather than pnpm. pnpm aggressive hoisting of dependencies can break native modules, such as mysql2— that your application may rely on. npm flatter, more predictable node_modules layout helps ensure native packages load correctly.
一般指南
🌐 General guidelines
硬件和软件要求
🌐 Hardware and software requirements
为了为 Strapi 提供尽可能最佳的环境,以下要求适用于开发(本地)以及登台和生产工作流程。
🌐 To provide the best possible environment for Strapi the following requirements apply to development (local) and staging and production workflows.
在安装 Strapi 之前,你的计算机上必须安装以下要求:
🌐 Before installing Strapi, the following requirements must be installed on your computer:
- Node.js:仅支持 Active LTS or Maintenance LTS versions (目前为
v20、v22和v24)。Node 的奇数版本发布,称为 Node.js 的“当前”版本,不受支持(例如 v23、v25)。 - 你首选的 Node.js 包管理器:
- Python (如果使用 SQLite 数据库)
-
适用于你的操作系统的标准构建工具(在大多数基于 Debian 的系统上为
build-essentials包) -
服务器的硬件规范(CPU、RAM、存储):
| 硬件 | 推荐 | 最低 ||------|------|------|| CPU | 2核以上 | 1核 || 内存 | 4GB以上 | 2GB || 磁盘 | 32GB以上 | 8GB |
-
支持的数据库版本:
| 数据库 | 推荐 | 最低 ||------------|-------------|---------|| MySQL | 8.4 | 8.0 || MariaDB | 11.4 | 10.3 || PostgreSQL | 17.0 | 14.0 || SQLite | 3 | 3 |
Strapi 不支持 MongoDB(或任何 NoSQL 数据库),也不支持任何“云原生”数据库(例如 Amazon Aurora、Google Cloud SQL 等)。
🌐 Strapi does not support MongoDB (or any NoSQL databases), nor does it support any "Cloud Native" databases (e.g., Amazon Aurora, Google Cloud SQL, etc.).
有关与 Strapi 一起部署数据库的内容,请参阅 数据库指南。
🌐 Deploying databases along with Strapi is covered in the databases guide.
-
受支持的操作系统:
| 操作系统 | 推荐 | 最低 ||------------------|----------------|---------------|| Ubuntu (LTS) | 24.04 | 20.04 || Debian | 11.x | 10.x || RHEL | 10.x | 8.x || macOS | 26.0 | 11.x || Windows 桌面 | 11 | 10 || Windows 服务器 | 不支持 | 不支持 |
应用配置
🌐 Application Configuration
1. 配置
🌐 1. Configure
我们建议根据环境使用环境变量来配置你的应用,例如:
🌐 We recommend using environment variables to configure your application based on the environment, for example:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
});
当你创建新项目时,Strapi 会生成一个带有默认值的 .env 文件。你可以编辑此文件或在所选的部署平台中设置变量(参见 示例 .env 文件):
🌐 Strapi generates a .env file with default values when you create a new project. You can edit this file or set variables in your chosen deployment platform (see example .env file):
HOST=10.0.0.1
PORT=1338
要了解更多关于配置的详细信息,请参阅 配置 文档。
🌐 To learn more about configuration details, see the configurations documentation.
2. 启动服务器
🌐 2. Launch the server
在生产中运行服务器之前,你需要构建生产管理面板:
🌐 Before running your server in production you need to build your admin panel for production:
- yarn
- npm
- windows
NODE_ENV=production yarn build
NODE_ENV=production npm run build
npm install cross-env
然后在你的 package.json 脚本部分:
🌐 Then in your package.json scripts section:
"build:win": "cross-env NODE_ENV=production npm run build",
然后运行:
🌐 And run:
npm run build:win
使用 production 设置运行服务器:
🌐 Run the server with the production settings:
- yarn
- npm
- windows
NODE_ENV=production yarn start
NODE_ENV=production npm run start
npm install cross-env
然后在你的 package.json 脚本部分:
🌐 Then in your package.json scripts section:
"start:win": "cross-env NODE_ENV=production npm start",
然后运行:
🌐 And run:
npm run start:win
我们强烈推荐使用 pm2 来管理你的流程。
如果你需要一个 server.js 文件来运行 node server.js 而不是 npm run start,那么请创建一个 ./server.js 文件,如下所示:
🌐 If you need a server.js file to be able to run node server.js instead of npm run start then create a ./server.js file as follows:
const strapi = require('@strapi/strapi');
strapi.createStrapi(/* {...} */).start();
如果你正在开发一个基于 TypeScript 的项目,必须提供 distDir 选项来启动服务器。
欲了解更多信息,请查阅 TypeScript 文档。
🌐 If you are developing a TypeScript-based project you must provide the distDir option to start the server.
For more information, consult the TypeScript documentation.
Strapi 在 /_health 提供了一个轻量级的健康检查路径,用于运行时间监控和负载均衡器。当服务器准备就绪时,它会返回一个 HTTP 204 No Content 状态和一个 strapi: You are so French! 头值,你可以使用它来确认应用可访问。
🌐 Strapi exposes a lightweight health check route at /_health for uptime monitors and load balancers. When the server is ready, it responds with an HTTP 204 No Content status and a strapi: You are so French! header value, which you can use to confirm the application is reachable.
高级配置
🌐 Advanced configurations
如果你想将管理界面托管在不同于 API 的服务器上,请查看此专门部分。
🌐 If you want to host the administration on another server than the API, please take a look at this dedicated section.
附加资源
🌐 Additional resources
Strapi 网站的 integrations page 包含有关如何将 Strapi 与许多资源集成的信息,包括如何在以下第三方平台上部署 Strapi:
在 AWS 上部署 Strapi
在 Azure 上部署 Strapi
在 DigitalOcean 应用平台上部署 Strapi
在 Heroku 上部署 Strapi
此外,社区维护的关于其他提供商的指南可在 Strapi Forum获得。这包括以下指南:
使用 Caddy 进行代理
使用 HAProxy 进行代理
使用 NGinx 进行代理
使用 PM2 进程管理器
以下外部指南(非 Strapi 官方维护)可能也有助于在各种环境中部署 Strapi:
🌐 The following external guide(s), not officially maintained by Strapi, might also help deploy Strapi on various environments:
[微软社区] 在 Azure 上部署
如果你在寻找多租户选项,Strapi 博客有一个 comprehensive guide。