# Deploy Next.js



If every route can render at build time, deploy the exported files as a Serverless App. If a route needs a running Next.js server for request-time rendering, use Compute.

## Export a static site [#export-a-static-site]

In your existing Next.js configuration, set `output: "export"` and `trailingSlash: true`. Run your project's build script and verify that `out/index.html` exists. A nested route such as `/about/` should produce `out/about/index.html`.

Run `ccp init .` and commit the generated `cluster-handler.ts` and `cluster.toml`. The handler resolves exported HTML pages by route and returns HTTP 404 for missing pages.

Run `ccp dev` and open both the home page and a nested route. Check a missing route returns 404. CCP serves the exported JavaScript, CSS and images from the assets directory. Rebuild the Next.js project before each `ccp deploy`. If this checkout belongs to an existing App, run `ccp link` first.

## Run a Next.js server [#run-a-nextjs-server]

Build and publish a Linux x86-64 container image that starts your Next.js server on `0.0.0.0:3000`. Configure the service and deploy the published image.

```bash
ccp init . --image "$IMAGE_REF" --port 3000
ccp compute deploy
```

Commit the resulting Compute settings. On a fresh checkout, follow the [Compute linking instructions](/docs/ccp/compute) before redeploying.
