部署
¥Deployment
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 创建了数据结构,并通过内容管理器将一些数据添加到本地(开发)Strapi 实例,则可以利用 数据管理系统 将数据从 Strapi 实例传输到另一个实例。
¥If you already created a data 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 data structure locally, push your project to a git-based repository, deploy the changes to production, and only then add content to the production instance.
一般准则
¥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 版本(目前支持
v18
和v20
)。不支持 Node 的奇数版本(称为 Node.js 的 "current" 版本)(例如 v19、v21)。¥Node.js: Only Active LTS or Maintenance LTS versions are supported (currently
v18
andv20
). Odd-number releases of Node, known as "current" versions of Node.js, are not supported (e.g. v19, v21). -
你首选的 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-essentials
package 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) 22.04 20.04 德班 11.x 10.x CentOS/RHEL 9.x 8.x 苹果系统 11.0 10.15 Windows 桌面 11 10 Windows 服务器 2022 2019
应用配置
¥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),
});
然后你可以创建 .env
文件或直接在你选择的部署平台中设置环境变量:
¥Then you can create a .env
file or directly set environment variables in your chosen deployment platform:
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.
高级配置
¥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: