常见问题
🌐 Frequently asked questions
Page summary:常见问题解答,涵盖常见的 Strapi 主题,包括内容类型管理、部署、身份验证、数据库处理、无服务器限制、插件、Docker、SSL 配置、TypeScript 支持和功能可用性。
🌐 Frequently asked questions covering common Strapi topics including content-type management, deployment, authentication, database handling, serverless limitations, plugins, Docker, SSL configuration, TypeScript support, and feature availability.
以下是你在使用 Strapi 时可能遇到的最常见问题的答案和解决方案。
🌐 Below are answers and solutions to most common issues that you may experience when working with Strapi.
为什么我不能在生产/预发布环境中创建或更新内容类型?
🌐 Why can't I create or update content-types in production/staging?
Strapi 将模型配置文件(定义模型架构的文件)存储在诸如 ./src/api/restaurant/content-types/restaurant/schema.json 的文件中。由于 Node.js 的工作方式,为了使更改生效,必须重新启动 Node 服务器。这可能会导致生产服务的停机,同样,这些更改应该在某种源代码管理中进行跟踪。
🌐 Strapi stores model configuration files (what defines the model schema) in files such as ./src/api/restaurant/content-types/restaurant/schema.json. Due to how Node.js works, in order for changes to take effect, that would require Node to restart the server. This could potentially cause downtime of your production service and likewise these changes should be tracked in some kind of source control.
通常你的开发“流程”会遵循以下路径:
🌐 Generally your "flow" of development would follow the following path:
- 开发 - 在本地主机上本地开发你的 Strapi 应用,然后将更改推送到源代码管理
- 暂存 - 将源代码控制中的更改部署到“类似生产”的环境中进行测试
- 生产 - 如果不需要其他更改,请部署到生产环境
- 根据需要重复,建议你正确版本化并测试你的应用
在此时及未来,没有计划允许在生产环境中创建或更新模型,并且目前也没有计划将模型设置迁移到数据库中。对此没有已知或推荐的解决方法。
🌐 At this time and in the future there is no plan to allow model creating or updating while in a production environment, and there is currently no plans to move model settings into the database. There are no known nor recommended workarounds for this.
Strapi 处理内容的部署或迁移吗?
🌐 Does Strapi handle deploying or migrating of content?
Strapi 确实提供了一个名为 数据传输 的功能,它允许你将内容从一个 Strapi 实例导出并导入到另一个实例,或者从文件存档导出和导入内容。这对于将内容从一个环境迁移到另一个环境非常有用。
🌐 Strapi does offer a feature known as Data Transfer that allows you to export and import content from one Strapi instance to another or exporting and importing from a file archive. This is useful for migrating content from one environment to another.
用户无法登录管理面板
🌐 User can't login to the admin panel
随着 Strapi 3.0 测试版的发布,发生了一个根本性的变化,即终端用户(REST 和 GraphQL 用户 )与管理员(管理面板用户)被分开,以至于普通用户无法被授予访问管理面板的权限。如果你想了解更多关于此更改原因的信息,你可以阅读 Strapi blog post 关于它的介绍。
Strapi 已发布了管理员和权限(RBAC - 基于角色的访问控制),它允许在一定程度上控制用户在管理员面板中可以访问的内容,并包括一些字段级别的权限。你还可以为角色赋予特定权限,例如内容类型、单一类型、插件和设置。
🌐 Strapi has released the Admin & Permissions (RBAC - Role-Based Access Control) that does allow for some degree of control over what users can access within the admin panel and includes some field level permissions. You can also give roles specific permissions for things like content-types, single types, plugins, and settings.
当我使用 HTTP 而不是 HTTPS 时,为什么管理员登录会失败?
🌐 Why does the admin login fail when I use HTTP instead of HTTPS?
从 v5.24.0 开始,Strapi 管理面板依赖安全的、仅限 HTTP 的 Cookie 来存储会话数据。浏览器拒绝在不安全的 HTTP 连接下存储或发送这些 Cookie,这意味着如果面板在没有 HTTPS 的情况下提供服务,管理员登录将无法完成。要恢复访问:
🌐 Starting from v5.24.0, the Strapi admin panel relies on secure, HTTP-only cookies to store session data. Browsers refuse to store or send these cookies over insecure HTTP connections, which means the admin login cannot complete if the panel is served without HTTPS. To restore access:
- 在 Strapi 前端终止 TLS(例如使用 Nginx、Caddy、Traefik、负载均衡器或云服务提供商),并通过 HTTPS 公开管理面板。
- 确保代理转发适当的头信息(例如
X-Forwarded-Proto),以便 Strapi 能够检测到安全连接。
使用内置 Strapi 服务器的本地开发仍可正常工作,因为开发配置未将 cookie 设置为安全。
🌐 Local development using the built-in Strapi server continues to work because the development configuration does not set the cookies as secure.
为什么我的应用在 PaaS 类型的服务上数据库和上传内容会重置?
🌐 Why are my application's database and uploads resetting on PaaS-type services?
如果你使用 --quickstart 创建了你的 Strapi 项目,默认情况下它使用 SQLite 数据库。PaaS 系统(Heroku、DigitalOcean Apps、Google App Engine 等)的文件系统通常是 ephemeral 或只读的,这意味着每次 dyno(容器)重置时,所有文件系统的更改都会丢失。由于 SQLite 和本地上 传的文件都存储在文件系统中,因此自上次 dyno 重置以来所做的任何更改都会被删除。通常,dyno 至少每天会重置一次,在大多数情况下,每天会多次重置,或者在将新代码推送到这些服务时会重置。
建议你使用像 Heroku 的 PostgreSQL 这样的数据库插件。对于文件上传,你将需要使用第三方提供商之一,例如 Cloudinary 或 AWS S3。
🌐 It is recommended you use a database add-on like Heroku's PostgreSQL. For file uploads, you will need to use one of the 3rd party providers such as Cloudinary or AWS S3.
我如何更改我的 Strapi Cloud 计划?
🌐 How can I change my Strapi Cloud plan?
使用 Strapi Cloud 项目设置中的 Plans 部分来升级或降级你的计划(参见 Cloud 文档中的 升级到另一个计划 和 降级到另一个计划)。
🌐 Use the Plans section of your Strapi Cloud project's settings to upgrade or downgrade your plan (see Upgrading to another plan and Downgrading to another plan in the Cloud documentation).