管理面板配置
¥Admin panel configuration
/config/admin
文件用于定义 Strapi 应用的 管理面板 配置。
¥The /config/admin
file is used to define the admin panel configuration for the Strapi application.
本页面可作为 /config/admin
文件中的所有配置参数和值的参考,按主题分组。有关每个功能工作原理的更多信息,请参阅每个子部分介绍中提供的链接。
¥The present page acts as a reference for all the configuration parameters and values that you can find in the /config/admin
file, grouped by topic. For additional information on how each feature works, please refer to links given in the introduction of each sub-section.
管理面板行为
¥Admin panel behavior
管理面板行为可以通过以下参数配置:
¥The admin panel behavior can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
autoOpen | 启用或禁用启动时打开管理。 | 布尔值 | true |
watchIgnoreFiles | 添加在开发期间不应监视的自定义文件。 查看更多 此处(属性 ignored )。 | array(string) | [] |
serveAdminPanel | 如果设置为 false,则不会提供管理面板。 注意: index.html 仍将提供服务 | 布尔值 | true |
管理面板的某些 UI 元素必须在 src/admin/app
文件中配置:
¥Some UI elements of the admin panel must be configured in the src/admin/app
file:
教程视频 要禁用包含教程视频的信息框,请将 config.tutorials
键设置为 false
。
¥Tutorial videos\ To disable the information box containing the tutorial videos, set the config.tutorials
key to false
.
发布通知 要禁用有关新 Strapi 版本的通知,请将 config.notifications.releases
键设置为 false
。
¥Releases notifications\ To disable notifications about new Strapi releases, set the config.notifications.releases
key to false
.
const config = {
// … other customization options go here
tutorials: false,
notifications: { releases: false },
};
export default {
config,
};
管理面板服务器
¥Admin panel server
默认情况下,Strapi 的管理面板通过 http://localhost:1337/admin
公开。出于安全原因,可以更新主机、端口和路径。
¥By default, Strapi's admin panel is exposed via http://localhost:1337/admin
. For security reasons, the host, port, and path can be updated.
管理面板的服务器配置可以使用以下参数进行配置:
¥The server configuration for the admin panel can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
url | 管理面板的访问路径。如果 URL 是相对的,它将与服务器 URL 连接起来。 示例: /dashboard 使管理面板可通过 http://localhost:1337/dashboard 访问。 | string | /admin |
host | 托管管理面板服务器。 | string | localhost |
port | 管理面板服务器的端口。 | string | 8000 |
如果你向 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).
仅更新管理面板的路径
¥Update the admin panel's path only
要使管理面板可在其他路径(例如 http://localhost:1337/dashboard
)访问,请定义或更新 url
属性:
¥To make the admin panel accessible at another path, for instance at http://localhost:1337/dashboard
, define or update the url
property:
module.exports = ({ env }) => ({
// … other configuration properties
url: "/dashboard",
});
由于默认情况下,后端服务器和管理面板服务器在同一主机和端口上运行,因此,如果你在后端 服务器配置 文件中保留 host
和 port
属性值不变,则只需更新 config/admin
文件即可。
¥Since by default the back-end server and the admin panel server run on the same host and port, only updating the config/admin
file should work if you left the host
and port
property values untouched in the back-end server configuration file.
更新管理面板的主机和端口
¥Update the admin panel's host and port
如果管理面板服务器和后端服务器不在同一台服务器上,则需要更新管理面板的主机和端口。例如,要在 my-host.com:3000
上托管管理面板:
¥If the admin panel server and the back-end server are not hosted on the same server, you will need to update the host and port of the admin panel. For example, to host the admin panel on my-host.com:3000
:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
host: "my-host.com",
port: 3000,
// Additionally you can define another path instead of the default /admin one 👇
// url: '/dashboard'
});
export default ({ env }) => ({
host: "my-host.com",
port: 3000,
// Additionally you can define another path instead of the default /admin one 👇
// url: '/dashboard'
});
在不同服务器上部署
¥Deploy on different servers
除非你选择将 Strapi 的后端服务器和管理面板服务器部署在不同的服务器上,否则默认情况下:
¥Unless you chose to deploy Strapi's back-end server and admin panel server on different servers, by default:
-
后端服务器和管理面板服务器均运行在同一主机和端口 (
http://localhost:1337/
) 上¥The back-end server and the admin panel server both run on the same host and port (
http://localhost:1337/
) -
管理面板可通过
/admin
路径访问,后端服务器可通过/api
路径访问¥The admin panel is accessible at the
/admin
path while the back-end server is accessible at the/api
path
要在完全不同的服务器上部署管理面板和后端,你需要同时配置服务器 (/config/server
) 和管 理面板 (/config/admin-panel
) 的配置。
¥To deploy the admin panel and the back-end on completely different servers, you need to configure both the server (/config/server
) and admin panel (/config/admin-panel
) configurations.
以下示例设置允许你从一个域提供管理面板,而 API 在另一个域上运行:
¥The following example setup allows you to serve the admin panel from one domain while the API runs on another:
- 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
});
使用此配置:
¥With this configuration:
-
管理面板可通过
http://yourfrontend.com
路径访问¥The admin panel will be accessible at
http://yourfrontend.com
-
面板的所有 API 请求都将发送到
http://yourbackend.com
。¥All API requests from the panel will be sent to
http://yourbackend.com
-
由于
serveAdminPanel: false
,后端服务器将不提供任何静态管理文件¥The backend server will not serve any static admin files due to
serveAdminPanel: false
API 令牌
¥API tokens
API 令牌 功能可以使用以下参数进行配置:
¥The API tokens feature can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
apiToken.salt | 用于生成 API 令牌的盐值 | string | 随机字符串 |
apiToken.secrets.encryptionKey | 用于设置 API 令牌在管理面板中可见性的加密密钥 | string | 随机字符串 |
审计日志
¥Audit logs
审核日志 功能可以使用以下参数进行配置:
¥The Audit Logs feature can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
auditLogs.enabled | 启用或禁用审计日志功能 | 布尔值 | true |
auditLogs.retentionDays | 审计日志的保存时长(以天为单位)。 自托管客户和 Strapi Cloud 客户的行为有所不同,请参阅表格下方的注释。 | integer | 90 |
对于 Strapi Cloud 客户,将使用存储在许可证信息中的 auditLogs.retentionDays
值,除非在 config/admin.js|ts
配置文件中定义了较小的 retentionDays
值。
¥For Strapi Cloud customers, the auditLogs.retentionDays
value stored in the license information is used, unless a smaller retentionDays
value is defined in the config/admin.js|ts
configuration file.
验证
¥Authentication
身份验证系统(包括 SSO 配置)可以通过以下参数配置:
¥The authentication system, including SSO configuration, can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
auth | 认证配置 | object | * |
auth.secret | 用于编码 JWT 令牌的秘密 | string | undefined |
auth.domain | 用于 SSO 身份验证的 cookie 中使用的域 EnterpriseThis feature is available with an Enterprise plan. SSOThis feature is available with the SSO add-on.) | string | undefined |
auth.providers | 用于单点登录 (SSO) 的身份验证提供程序列表 | array(object) | * |
auth.options | 传递给 jsonwebtoken 的选项对象 | object | * |
auth.options.expiresIn | jsonwebtoken 中使用的 JWT 过期时间 | object | 30d |
auth.events | 注册认证的所有事件订阅者的记录 | object | {} |
auth.events.onConnectionSuccess | 管理员用户成功登录管理面板时调用的函数 | function | undefined |
auth.events.onConnectionError | 管理员用户登录管理面板失败时调用的函数 | function | undefined |
功能标志
¥Feature flags
功能标志可以通过以下参数配置:
¥The feature flags can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
flags | 用于打开或关闭管理员的某些功能或元素的设置 | object | |
flags.nps | 启用/禁用净推荐值弹出窗口 | 布尔值 | true |
flags.promoteEE | 启用/禁用 Strapi Enterprise 功能的推广 | 布尔值 | true |
忘记密码
¥Forgot password
忘记密码功能(包括 电子邮件模板)可以使用以下参数进行配置:
¥The forgot password functionality, including email templating, can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
forgotPassword | 用于自定义忘记密码邮箱的设置 | object | |
forgotPassword.emailTemplate | 电子邮件插件中定义的电子邮件模板 | object | 默认模板 |
forgotPassword.from | 发送者邮件地址 | string | 默认值定义在你的提供程序配置中 |
forgotPassword.replyTo | 默认地址或要求收件人回应的地址 | string | 默认值定义在你的提供程序配置中 |
速率限制
¥Rate limiting
管理面板身份验证端点的速率限制可以使用以下参数进行配置。其他配置选项来自 koa2-ratelimit 软件包:
¥The rate limiting for the admin panel's authentication endpoints can be configured with the following parameters. Additional configuration options come from the koa2-ratelimit package:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
rateLimit | 用于自定义管理面板身份验证端点速率限制的设置 | object | |
rateLimit.enabled | 启用或禁用速率限制器 | 布尔值 | true |
rateLimit.interval | 请求被视为同一速率限制桶一部分的时间窗口 | object | { min: 5 } |
rateLimit.max | 时间窗口内允许的最大请求数 | integer | 5 |
rateLimit.delayAfter | 延迟响应之前允许的请求数 | integer | 1 |
rateLimit.timeWait | 响应请求之前等待的时间(以毫秒为单位) | integer | 3000 |
rateLimit.prefixKey | 速率限制键的前缀 | string | ${userEmail}:${ctx.request.path}:${ctx.request.ip} |
rateLimit.whitelist | 列入白名单以免受速率限制的 IP 地址数组 | array(string) | [] |
rateLimit.store | 速率限制存储位置(内存、Sequelize 或 Redis)。更多信息请参阅 koa2-ratelimit 文档 | object | MemoryStore |
转移令牌
¥Transfer tokens
可以使用以下参数配置 数据传输 功能的转移令牌:
¥Transfer tokens for the Data transfer feature can be configured with the following parameters:
范围 | 描述 | 类型 | 默认 |
---|---|---|---|
transfer.token.salt | 用于生成转账令牌的盐值。 如果未定义转账令牌盐值,转账功能将被禁用。 | string | 随机字符串 |
对于 Strapi Cloud 客户,将使用存储在许可证信息中的 auditLogs.retentionDays
值,除非在 config/admin.js|ts
配置文件中定义了较小的 retentionDays
值。
¥For Strapi Cloud customers, the auditLogs.retentionDays
value stored in the license information is used, unless a smaller retentionDays
value is defined in the config/admin.js|ts
configuration file.
配置举例
¥Configuration examples
/config/admin
文件至少应包含 authentication 和 API 令牌 所需参数的最小配置。可以包含附加参数以实现完整配置。
¥The /config/admin
file should at least include a minimal configuration with required parameters for authentication and API tokens. Additional parameters can be included for a full configuration.
环境配置(即使用 env()
辅助程序)不需要包含所有值,只要它们存在于默认 /config/server
中即可。
¥Environmental configurations (i.e. using the env()
helper) do not need to contain all the values so long as they exist in the default /config/server
.
- Minimal configuration
- Full configuration
使用任何新项目创建的默认配置至少应包括以下内容:
¥The default configuration created with any new project should at least include the following:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
apiToken: {
salt: env('API_TOKEN_SALT', 'someRandomLongString'),
},
auditLogs: { // only accessible with an Enterprise plan
enabled: env.bool('AUDIT_LOGS_ENABLED', true),
},
auth: {
secret: env('ADMIN_JWT_SECRET', 'someSecretKey'),
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
}
},
});
export default ({ env }) => ({
apiToken: {
salt: env('API_TOKEN_SALT', 'someRandomLongString'),
},
auditLogs: { // only accessible with an Enterprise plan
enabled: env.bool('AUDIT_LOGS_ENABLED', true),
},
auth: {
secret: env('ADMIN_JWT_SECRET', 'someSecretKey'),
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
}
},
});
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
apiToken: {
salt: env('API_TOKEN_SALT', 'someRandomLongString'),
secrets: {
encryptionKey: env('ENCRYPTION_KEY'),
},
},
auditLogs: { // only accessible with an Enterprise plan
enabled: env.bool('AUDIT_LOGS_ENABLED', true),
retentionDays: 120,
},
auth: {
events: {
onConnectionSuccess(e) {
console.log(e.user, e.provider);
},
onConnectionError(e) {
console.error(e.error, e.provider);
},
},
options: {
expiresIn: '7d',
},
secret: env('ADMIN_JWT_SECRET', 'someSecretKey'),
},
url: env('PUBLIC_ADMIN_URL', '/dashboard'),
autoOpen: false,
watchIgnoreFiles: [
'./my-custom-folder', // Folder
'./scripts/someScript.sh', // File
],
host: 'localhost',
port: 8003,
serveAdminPanel: env.bool('SERVE_ADMIN', true),
forgotPassword: {
from: 'no-reply@example.com',
replyTo: 'no-reply@example.com',
},
rateLimit: {
interval: { hour: 1, min: 30 },
timeWait: 3*1000,
max: 10,
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
}
},
});
export default ({ env }) => ({
apiToken: {
salt: env('API_TOKEN_SALT', 'someRandomLongString'),
secrets: {
encryptionKey: env('ENCRYPTION_KEY'),
},
},
auditLogs: { // only accessible with an Enterprise plan
enabled: env.bool('AUDIT_LOGS_ENABLED', true),
retentionDays: 120,
},
auth: {
events: {
onConnectionSuccess(e) {
console.log(e.user, e.provider);
},
onConnectionError(e) {
console.error(e.error, e.provider);
},
},
options: {
expiresIn: '7d',
},
secret: env('ADMIN_JWT_SECRET', 'someSecretKey'),
},
url: env('PUBLIC_ADMIN_URL', '/dashboard'),
autoOpen: false,
watchIgnoreFiles: [
'./my-custom-folder', // Folder
'./scripts/someScript.sh', // File
],
host: 'localhost',
port: 8003,
serveAdminPanel: env.bool('SERVE_ADMIN', true),
forgotPassword: {
from: 'no-reply@example.com',
replyTo: 'no-reply@example.com',
},
rateLimit: {
interval: { hour: 1, min: 30 },
timeWait: 3*1000,
max: 10,
},
transfer: {
token: {
salt: env('TRANSFER_TOKEN_SALT', 'anotherRandomLongString'),
}
},
});