管理面板自定义:主机、端口和路径配置
🌐 Admin panel customization: Host, port, and path configuration
默认情况下,Strapi 的 管理面板 通过 http://localhost:1337/admin 暴露。出于安全原因,可以更新主机、端口和路径。
仅更新管理员面板的路径
🌐 Update the admin panel's path only
除非你选择将 Strapi 的后端服务器和管理面板服务器部署在不同的服务器上(参见 部署),否则默认情况下:
🌐 Unless you chose to deploy Strapi's back-end server and admin panel server on different servers (see deployment), by default:
- Strapi 的后端服务器和管理面板服务器都运行在相同的主机和端口上,即
http://localhost:1337/。 - 管理员面板可以通过
/admin路径访问,而后端服务器可以通过/api路径访问。
要使管理面板可以通过另一路径访问,例如在 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 in the admin panel configuration file as follows:
module.exports = ({ env }) => ({
// … other configuration properties
url: "/dashboard",
});
由于默认情况下,后端服务器和管理面板服务器在同一主机和端口上运行,如果你在服务器配置文件中未更改host和port属性值,只更新config/admin.[ts|js]文件应该就可以工作,配置应如下所示:
🌐 Since by default the back-end server and the admin panel server run on the same host and port, only updating the config/admin.[ts|js] file should work if you left the host and port property values untouched in the server configuration file, which should be as follows:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
});
export default ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
});
更新管理员面板的主机和端口
🌐 Update the admin panel's host and port
如果 Strapi 的管理面板和后端服务器没有托管在同一台服务器上(参见 deployment),你需要更新管理面板的主机和端口。
🌐 If the admin panel and the back-end server of Strapi are not hosted on the same server (see deployment), you will need to update the host and port of the admin panel.
这是在管理员面板配置文件中完成的,例如,要在 my-host.com:3000 上托管管理员面板,应按如下方式更新属性:
🌐 This is done in the admin panel configuration file, for example to host the admin panel on my-host.com:3000 properties should be updated follows:
- 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'
});
/config/admin.[ts|js] 文件可以用于配置许多其他方面。详情请参阅 管理面板配置 文档。
🌐 The /config/admin.[ts|js] file can be used to configure many other aspects. Please refer to the admin panel configuration documentation for details.
当从与 API 不同的公共来源(域名、主机或端口)访问管理端时,相应设置 host/port,并确保你的代理转发头信息(例如,X-Forwarded-*)。如果管理端可通过不同来源访问,优先显式配置该来源。
🌐 When serving the admin from a different public origin (domain, host, or port) than the API, set host/port accordingly and ensure your proxy forwards headers (e.g., X-Forwarded-*). If the admin is reachable at a different origin, prefer configuring that origin explicitly.