部署
¥Deployment
Page summary:
Deployment options cover hardware/software prerequisites, environment variable setup, and building the admin panel before launch. In the documentation: links to provider‑specific and advanced guides to help pick the right hosting strategy.
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 云 快速部署和托管你的项目。
¥You can use Strapi Cloud to quickly deploy and host your project.
如果你已经使用 Content-Type Builder 创建了内容结构,并通过 Content Manager 将一些数据添加到本地(开发)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:仅支持 活动 LTS 或维护 LTS 版本(目前支持
v20和v22)。不支持 Node 的奇数版本(称为 Node.js 的 "current" 版本)(例如 v21、v23)。¥Node.js: Only Active LTS or Maintenance LTS versions are supported (currently
v20andv22). Odd-number releases of Node, known as "current" versions of Node.js, are not supported (e.g. v21, v23). -
你首选的 Node.js 包管理器:
¥Your preferred Node.js package manager:
-
Python(如果使用 SQLite 数据库)
¥Python (if using a SQLite database)
-
适用于你的操作系统的标准构建工具(大多数基于 Debian 的系统上的
build-essentials包)¥Standard build tools for your OS (the
build-essentialspackage on most Debian-based systems) -
服务器的硬件规范(CPU、RAM、存储):
¥Hardware specifications for your server (CPU, RAM, storage):
硬件 受到推崇的 最低限度 中央处理器 2+ 核心 1 核 记忆 4GB+ 2GB 磁盘 32GB+ 8GB -
支持的数据库版本:
¥A supported database version:
数据库 受到推崇的 最低限度 MySQL 8.0 8.0 玛丽亚数据库 10.6 10.5 PostgreSQL 14.0 12.0 SQLite 3 3
数据库指南 中介绍了与 Strapi 一起部署数据库。
¥Deploying databases along with Strapi is covered in the databases guide.
-
支持的操作系统:
¥A supported operating system:
操作系统 受到推崇的 最低限度 乌班图 (LTS) 24.04 20.04 德班 11.x 10.x RHEL 10.x 8.x 苹果系统 26.0 11.x Windows 桌面 11 10 Windows 服务器 不支持 不支持
应用配置
¥Application Configuration
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
要了解有关配置详细信息的更多信息,请参阅 configurations 文档。
¥To learn more about configuration details, see the configurations documentation.
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
如果你需要 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 项目是 created,其代码托管在 GitHub 上。
¥Your Strapi project is created and its code is hosted on GitHub.
-
你已阅读 一般部署指南。
¥You have read the general deployment guidelines.
Strapi 网站的 集成页面 包含有关如何将 Strapi 与许多资源集成的信息,包括如何在以下第三方平台上部署 Strapi:
¥The integrations page of the Strapi website include information on how to integrate Strapi with many resources, including how to deploy Strapi on the following 3rd-party platforms:
Deploy Strapi on AWS
Deploy Strapi on Azure
Deploy Strapi on DigitalOcean App Platform
Deploy Strapi on Heroku
此外,社区维护的其他提供商指南可在 Strapi 论坛 中找到。这包括以下指南:
¥In addition, community-maintained guides for additional providers are available in the Strapi Forum. This includes the following guides:
Proxying with Caddy
Proxying with HAProxy
Proxying with NGinx
Using the PM2 process manager
以下外部指南(非 Strapi 官方维护)可能也有助于在各种环境中部署 Strapi:
¥The following external guide(s), not officially maintained by Strapi, might also help deploy Strapi on various environments:
[Microsoft Community] Deploying on Azure
如果你正在寻找多租户选项,Strapi 博客有一个 综合指南。
¥If you're looking for multi-tenancy options, the Strapi Blog has a comprehensive guide.