> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# server.base

- **类型：** `string`
- **默认值：** `/`

`server.base` 用于配置服务器的 [基础路径](/zh/guide/basic/server.md#base-path)。

## 示例

默认情况下，Rsbuild 服务器的基础路径是 `/`，你可以通过 [http://localhost:3000/](http://localhost:3000/) 访问 `index.html` 等输出文件，以及 [public 目录](/zh/guide/basic/static-assets.md#public-folder) 下的资源。

当你希望通过 `http://localhost:3000/foo/` 访问到 `index.html` 时，可以将 `server.base` 修改为 `/foo`。

```ts title="rsbuild.config.ts"
export default {
  server: {
    base: '/foo',
  },
};
```

## 静态资源 URL 前缀

[dev.assetPrefix](/zh/config/dev/asset-prefix.md) 和 [output.assetPrefix](/zh/config/output/asset-prefix.md) 会读取 `server.base` 的值作为默认值。

当 `server.base` 为 `/foo` 时，默认在浏览器中加载的资源 URL 如下：

```html
<script defer src="/foo/static/js/index.js"></script>
```

此时，可以通过 `http://localhost:3000/foo/` 访问到 `index.html` 以及其他静态资源产物。

如果你不希望使用此默认行为，可以通过显式设置 `dev.assetPrefix` / `output.assetPrefix` 来覆盖：

```ts title="rsbuild.config.ts"
export default {
  dev: {
    assetPrefix: '/',
  },
  output: {
    assetPrefix: 'https://cdn.example.com/assets/',
  },
  server: {
    base: '/foo',
  },
};
```
