管理面板部署
¥Admin panel deployment
Strapi 的前端部分称为管理面板。管理面板提供了一个图形用户界面,可帮助你构建和管理可通过 Strapi 的 Content API 访问应用自己的前端的内容。
¥The front-end part of Strapi is called the admin panel. The admin panel presents a graphical user interface to help you structure and manage the content that will be accessible to your application's own front-end through Strapi's Content API.
管理面板是一个基于 React 的单页应用,它封装了 Strapi 应用的所有功能和已安装的插件。
¥The admin panel is a React-based single-page application that encapsulates all the features and installed plugins of a Strapi application.
Strapi 的 后端服务器 提供内容 API,为你的内容提供端点。
¥The back-end server of Strapi serves the Content API which provides endpoints to your content.
默认情况下,后端服务器和管理面板服务器部署在同一台服务器上。但管理面板和后端服务器是独立的,可以部署在不同的服务器上,这给我们带来了不同的场景:
¥By default, the back-end server and the admin panel server are deployed on the same server. But the admin panel and the back-end server are independent and can be deployed on different servers, which brings us to different scenarios:
-
将整个项目部署在同一服务器上。
¥Deploy the entire project on the same server.
-
在与 API 服务器不同的服务器(AWS S3、Azure 等)上部署管理面板。
¥Deploy the administration panel on a server (AWS S3, Azure, etc) different from the API server.
每种情况的构建配置都不同。
¥Build configurations differ for each case.
在部署之前,需要通过从项目的根目录运行以下命令来构建管理面板:
¥Before deployment, the admin panel needs to be built, by running the following command from the project's root directory:
- yarn
- npm
yarn build
npm run build
这将替换位于 ./build
的文件夹内容。请访问 http://localhost:1337/admin 以确保已考虑定制。
¥This will replace the folder's content located at ./build
. Visit http://localhost:1337/admin to make sure customizations have been taken into account.
同一服务器
¥Same server
在同一台服务器上部署 Strapi 的管理面板和后端(API)是默认行为。构建配置将自动设置。服务器将在定义的端口上启动,并且可以通过 http://yourdomain.com:1337/admin
访问管理面板。
¥Deploying the admin panel and the back end (API) of Strapi on the same server is the default behavior. The build configuration will be automatically set. The server will start on the defined port and the administration panel will be accessible through http://yourdomain.com:1337/admin
.
不同的服务器
¥Different servers
要在不同的服务器上部署 Strapi 的管理面板和后端(API),请使用以下配置:
¥To deploy the admin panel and the back end (API) of Strapi on different servers, use the following configuration:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
url: "http://yourbackend.com",
});
module.exports = ({ env }) => ({
/**
* Note: The administration will be accessible from the root of the domain
* (ex: http://yourfrontend.com/)
*/
url: "/",
serveAdminPanel: false, // http://yourbackend.com will not serve any static admin files
});
export default ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
url: "http://yourbackend.com",
});
export default ({ env }) => ({
/**
* Note: The administration will be accessible from the root of the domain
* (ex: http://yourfrontend.com/)
*/
url: "/",
serveAdminPanel: false, // http://yourbackend.com will not serve any static admin files
});
使用此配置运行 yarn build
后,将创建/覆盖 build
文件夹。使用此文件夹从具有你选择的域(例如 http://yourfrontend.com
)的另一台服务器提供服务。
¥After running yarn build
with this configuration, the build
folder will be created/overwritten. Use this folder to serve it from another server with the domain of your choice (e.g. http://yourfrontend.com
).
管理 URL 将为 http://yourfrontend.com
,来自面板的每个请求都将到达 http://yourbackend.com
的后端。
¥The administration URL will then be http://yourfrontend.com
and every request from the panel will hit the backend at http://yourbackend.com
.
如果你向 url
选项添加路径,它不会为你的应用添加前缀。为此,请使用 Nginx 等代理服务器(请参阅 可选软件部署指南)。
¥If you add a path to the url
option, it won't prefix your application. To do so, use a proxy server like Nginx (see optional software deployment guides).