管理面板自定义:主机、端口和路径配置
¥Admin panel customization: Host, port, and path configuration
默认情况下,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.
仅更新管理面板的路径
¥Update the admin panel's path only
除非你选择在不同的服务器上部署 Strapi 的后端服务器和管理面板服务器(参见 deployment),否则默认情况下:
¥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/
。¥The back-end server and the admin panel server of Strapi both run on the same host and port, which is
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.
要使管理面板可从其他路径访问,例如 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.