Skip to main content

多区域

Examples

区域是 Next.js 应用的单个部署。你可以拥有多个区域并将它们合并为一个应用。

¥A zone is a single deployment of a Next.js app. You can have multiple zones and merge them as a single app.

例如,假设你有以下应用:

¥For example, let's say you have the following apps:

  • 一个为 /blog/** 提供服务的应用

    ¥An app for serving /blog/**

  • 另一个用于服务所有其他页面的应用

    ¥Another app for serving all other pages

借助多区域支持,你可以将这两个应用合并为一个应用,允许你的客户使用单个 URL 浏览它,但你可以独立开发和部署这两个应用。

¥With multi zones support, you can merge both these apps into a single one allowing your customers to browse it using a single URL, but you can develop and deploy both apps independently.

如何定义区域

¥How to define a zone

没有与区域相关的 API。你只需执行以下操作:

¥There are no zone related APIs. You only need to do the following:

  • 确保仅保留应用中你需要的页面,这意味着应用不能拥有另一个应用的页面,如果应用 A/blog,那么应用 B 也不应该有它。

    ¥Make sure to keep only the pages you need in your app, meaning that an app can't have pages from another app, if app A has /blog then app B shouldn't have it too.

  • 确保配置 basePath 以避免与页面和静态文件发生冲突。

    ¥Make sure to configure a basePath to avoid conflicts with pages and static files.

如何合并区域

¥How to merge zones

你可以在其中一个应用或任何 HTTP 代理中使用 rewrites 合并区域。

¥You can merge zones using rewrites in one of the apps or any HTTP proxy.

对于 Vercel 上的 Next.js 应用,你可以使用 monorepo 通过单个 git push 部署这两个应用。

¥For Next.js on Vercel applications, you can use a monorepo to deploy both apps with a single git push.