Skip to main content

部署

¥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 云

你可以使用 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 版本(目前支持 v18v20)。不支持 Node 的奇数版本(称为 Node.js 的 "current" 版本)(例如 v19、v21)。

    ¥Node.js: Only Active LTS or Maintenance LTS versions are supported (currently v18 and v20). 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:

    数据库受到推崇的最低限度
    MySQL8.08.0
    玛丽亚数据库10.610.5
    PostgreSQL14.012.0
    SQLite33
数据库部署

数据库指南 中介绍了与 Strapi 一起部署数据库。

¥Deploying databases along with Strapi is covered in the databases guide.

  • 支持的操作系统:

    ¥A supported operating system:

    操作系统受到推崇的最低限度
    乌班图 (LTS)22.0420.04
    德班11.x10.x
    CentOS/RHEL9.x8.x
    苹果系统11.010.15
    Windows 桌面1110
    Windows 服务器20222019

应用配置

¥Application Configuration

1. 配置

¥ Configure

我们建议根据环境使用环境变量来配置你的应用,例如:

¥We recommend using environment variables to configure your application based on the environment, for example:

/config/server.js

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:

NODE_ENV=production yarn build

使用 production 设置运行服务器:

¥Run the server with the production settings:

NODE_ENV=production yarn start
提醒

我们强烈建议使用 pm2 来管理你的流程。

¥We highly recommend using pm2 to manage your process.

如果你需要 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:

path: ./server.js



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

Prerequisites

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:


此外,Strapi 论坛 中还提供了社区维护的其他提供商指南。这包括以下指南:

¥In addition, community-maintained guides for additional providers are available in the Strapi Forum. This includes the following guides: