# 管理面板自定义 - URL、主机和路径配置

> Source: https://strapi.nodejs.cn/cms/admin-panel-customization/host-port-path

🌐 Admin panel customization: Host, port, and path configuration

在 `config/admin.[ts|js]` 文件中配置 Strapi 管理面板的主机、端口和 URL 路径，以更改其默认位置 `/admin` 的访问位置。

🌐 Configure the Strapi admin panel's host, port, and URL path in the `config/admin.[ts|js]` file to change where it is accessible from its default location at `/admin`.

默认情况下，Strapi 的 [管理面板](/cms/admin-panel-customization) 通过 [http://localhost:1337/admin](http://localhost:1337/admin) 暴露。出于安全原因，可以更新主机、端口和路径。

## 仅更新管理员面板的路径 {#update-the-admin-panels-path-only}

🌐 Update the admin panel's path only

除非你选择将 Strapi 的后端服务器和管理面板服务器部署在不同的服务器上（参见 [部署](/cms/configurations/admin-panel#deploy-on-different-servers)），否则默认情况下：

🌐 Unless you chose to deploy Strapi's back-end server and admin panel server on different servers (see [deployment](/cms/configurations/admin-panel#deploy-on-different-servers)), by default:

- Strapi 的后端服务器和管理面板服务器都运行在相同的主机和端口上，即 `http://localhost:1337/`。
- 管理员面板可以通过 `/admin` 路径访问，而后端服务器可以通过 `/api` 路径访问。

要使管理面板可以通过另一路径访问，例如在 `http://localhost:1337/dashboard`，请在[管理面板配置文件](/cms/configurations/admin-panel)中定义或更新 `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](/cms/configurations/admin-panel) as follows:

```js title="/config/admin.js"
module.exports = ({ env }) => ({
  // … other configuration properties
  url: "/dashboard",
});
```

由于默认情况下，后端服务器和管理面板服务器在同一主机和端口上运行，如果你在[服务器配置](/cms/configurations/server)文件中未更改`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](/cms/configurations/server) file, which should be as follows:

```js title="/config/server.js"
module.exports = ({ env }) => ({
  host: env("HOST", "0.0.0.0"),
  port: env.int("PORT", 1337),
});
```

```js title="/config/server.ts"

  host: env("HOST", "0.0.0.0"),
  port: env.int("PORT", 1337),
});
```

## 更新管理员面板的主机和端口 {#update-the-admin-panels-host-and-port}

🌐 Update the admin panel's host and port

如果 Strapi 的管理面板和后端服务器没有托管在同一台服务器上（参见 [deployment](/cms/configurations/admin-panel#deploy-on-different-servers)），你需要更新管理面板的主机和端口。

🌐 If the admin panel and the back-end server of Strapi are not hosted on the same server (see [deployment](/cms/configurations/admin-panel#deploy-on-different-servers)), 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:

```js title="./config/admin.js"
module.exports = ({ env }) => ({
  host: "my-host.com",
  port: 3000,
  // Additionally you can define another path instead of the default /admin one 👇
  // url: '/dashboard' 
});
```

```js title="./config/admin.ts"

  host: "my-host.com",
  port: 3000,
  // Additionally you can define another path instead of the default /admin one 👇
  // url: '/dashboard'
});
```

<br/>

:::strapi Other admin panel configurations

`/config/admin.[ts|js]` 文件可以用于配置许多其他方面。详情请参阅 [管理面板配置](/cms/configurations/admin-panel) 文档。

🌐 The `/config/admin.[ts|js]` file can be used to configure many other aspects. Please refer to the [admin panel configuration](/cms/configurations/admin-panel) documentation for details.

:::

:::tip Behind a reverse proxy

当从与 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.

:::
