**Tags:** "Hello World" Examples · Next.js

# Next Static Hello World

A ready-to-deploy [Next.js](https://nextjs.org) Hello World recipe for [Zerops](https://zerops.io), showcasing static export mode — built with Node.js and served by Nginx, with environment configurations covering every stage of the development lifecycle.

### Available Environments

- [AI Agent](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=ai-agent)
- [Remote (CDE)](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=remote-cde)
- [Local](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=local)
- [Stage](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=stage)
- **Small Production** ← current
- [Highly-available Production](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=highly-available-production)

### Services in this Environment

**Services:**

- **core** (core@1)
  - Containers: 1 × Shared Core, 0.00 GB RAM, 0 GB Disk
- **app** (static)
  - Containers: 2 × Shared Core, 0.38 GB RAM, 1 GB Disk
  - Repository: [zerops-recipe-apps/nextjs-static-hello-world-app](https://github.com/zerops-recipe-apps/nextjs-static-hello-world-app)

**Total Resources:** 3 containers, 0.75 GB RAM, 2 GB Disk

### One-Click Deploy (Import YAML)

Use this YAML with `zcli project import` to deploy this environment:

```yaml
# Next.js Hello World — Small Production Environment
#
# Production-ready setup optimized for moderate throughput.
# Two containers run at all times for availability and
# load distribution across requests.

project:
  name: nextjs-static-hello-world-small-prod

services:
  # Production service — Nginx serves the static export
  # across two containers, with Zerops autoscaling RAM
  # within the configured bounds as traffic changes.
  - hostname: app
    type: static
    # 'prod' setup: runs 'npm ci && npm run build', bakes
    # NEXT_PUBLIC_APP_ENV=production into the static output,
    # and deploys the 'out/' directory to Nginx.
    zeropsSetup: prod
    # Zerops pulls source code and zerops.yaml from this
    # public repo and triggers the build/deploy pipeline.
    buildFromGit: https://github.com/zerops-recipe-apps/nextjs-static-hello-world-app
    enableSubdomainAccess: true
    # Always run at least 2 containers — ensures availability
    # during deploys (zero-downtime switchover) and spreads
    # traffic across multiple Nginx instances.
    minContainers: 2
    # Zerops autoscales RAM within these bounds every 10s.
    # minFreeRamGB reserves headroom for Nginx worker
    # processes and traffic spikes above the baseline.
    verticalAutoscaling:
      minRam: 0.25
      minFreeRamGB: 0.125

```

---

## Next Steps

After deploying one of the environments and getting to know Zerops, you have two paths to choose from:

1. **Template Flow** — Clone our GitHub repositories and use the whole recipe as a template
2. **Integrate Flow** — If you already have an existing application on a similar stack, integrate the recipe setup with your application

Select a flow: [Template Flow](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=small-production&guideFlow=template) or [Integrate Flow](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=small-production&guideFlow=integrate)

Both flows are shown below:

## How to take over the Small Production environment

### 📦 Clone the template repositories

Fork or clone the following repositories to your local machine or GitHub account:

- [zerops-recipe-apps/nextjs-static-hello-world-app](https://github.com/zerops-recipe-apps/nextjs-static-hello-world-app)

### 1. Find your service name

Many commands and configurations need the exact name of your service. You can find it in the Zerops Dashboard.

- Open your project in the Zerops Dashboard.
- In the project overview, find the service you want to manage.
- Use this exact name whenever a command or pipeline configuration asks for `<service-name>`.

<img src="https://storage-prg1.zerops.io/4gfos-storage/copy1_cd2a6044c8.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Locating the Service Name" width="500" />

### 2. Configure deployment pipeline

Go to Service Settings > Pipelines & CI/CD Settings in the Zerops Dashboard and connect your repository.

For production, use a trigger on new tags. This keeps deployments intentional and tied to a specific version. You can also add a regex filter, such as `^v[0-9]+\.[0-9]+\.[0-9]+$`, if you want to allow only semantic version tags.

<img src="https://storage-prg1.zerops.io/4gfos-storage/triggerborder_b865860a89.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Triggers" width="500" />

Alternatively, add `zcli push` to your existing CI/CD pipeline if you want full control over when deployments happen.

Learn more about pipeline triggers: https://docs.zerops.io/features/pipeline

### 3. Deploy to production

Create and push a new Git tag to deploy a specific version of your app:

```bash
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
```

> [!TIP]
> Open the pipeline detail in the Zerops Dashboard to check the build progress and verify that all steps finish successfully.

### 4. Configure autoscaling

Review the autoscaling settings for your runtime services and databases in Service Settings > Automatic Scaling Configuration in the Zerops Dashboard.

<img src="https://storage-prg1.zerops.io/4gfos-storage/scaling_ac0880aef5.png" style="display: block; margin: 0 auto;" alt="Zerops GUI: Autoscaling configuration" width="500" />

The most important settings are:

```yaml
verticalAutoscaling:
  minRam: 1
  minFreeRamGB: 0.5
  minFreeRamPercent: 20
```

> [!CAUTION]
> Pay attention to `minFreeRamGB`. This value tells Zerops when to scale RAM vertically. Adjust it based on your app’s real memory needs. RAM scales up immediately, while CPU scales after two consecutive measurements below the threshold.

> [!TIP]
> Run a quick stress test with a tool like hey before real users arrive. This helps you see how your app behaves under load and tune the autoscaling settings.

### 5. Set up your domain

To send real traffic to your app, configure public HTTP access in Service Settings > Public Access & Internal Ports in the Zerops Dashboard.

Add your custom domain and point your DNS records to the Zerops IPs shown in the dashboard:

<img src="https://storage-prg1.zerops.io/4gfos-storage/subdomain_8cafd801e8.jpg" style="display: block; margin: 0 auto;" alt="Zerops GUI: Public access and custom domain" width="500" />

```text
Type   Name          Content          TTL
A      example.com   <zerops-ipv4>    Auto
AAAA   example.com   <project-ipv6>   Auto
```

For wildcard domains, add a CNAME record for SSL validation.

Check the public access documentation: https://docs.zerops.io/features/access

> [!TIP]
> When changing DNS records for production, start with a low TTL value. Make sure SSL certificates are active before you disable the fallback Zerops subdomain.

Once everything works, you can disable the Zerops subdomain so all traffic goes through your custom domain.

---

### 🎉 You are good to go!

Your application is live in production and the core setup is complete.

The following sections are optional. They cover extra production features such as log forwarding, backups, and diagnostic access. You can stop here and come back later when you need them.

---

### 6. Set up log forwarding (Optional)

To send logs to an external service, go to Project Settings > Log Forwarding & Logs Overview in the Zerops Dashboard.

You can forward logs to services like Better Stack, Papertrail, or your own self-hosted solution.

Learn more about log forwarding: https://docs.zerops.io/references/logging

### 7. Configure database backups (Optional)

Manage automated encrypted backups in Service Settings > Backups in the Zerops Dashboard.

By default, backups run daily between 00:00 and 01:00 UTC.

Before a major deployment, create a manual protected backup:

```bash
zcli backup create <db-service> --tags pre-deploy,protected
```

Read the backup documentation for more options: https://docs.zerops.io/features/backup

### 8. Set up diagnostic access (Optional)

Use zCLI and VPN access when you need to inspect or maintain services directly.

For runtime services:

```bash
zcli vpn up
ssh <service-name>.zerops
```

For databases, connect through the VPN to reach the project’s private network, or set up secure direct IP access for your database admin tools.

Check the VPN documentation: https://docs.zerops.io/references/cli/commands#vpn-up

## How to integrate app with Zerops

### 1. Adding `zerops.yaml`
The main application configuration file you place at the root of your repository, it tells Zerops how to build, deploy and run your application.

```yaml
# Build with Node.js (npm/npx), serve with Nginx.
# The build container compiles Next.js into static
# HTML/CSS/JS — Node.js is NOT present at runtime.
zerops:
  - setup: prod
    build:
      base: nodejs@22

      # NEXT_PUBLIC_* vars are baked into the static
      # output at build time — there is no runtime
      # process to read env vars in static deployments.
      envVariables:
        NEXT_PUBLIC_APP_ENV: production

      buildCommands:
        - npm ci
        - npm run build

      # Strip 'out/' prefix — contents become the Nginx
      # root. Requires 'output: export' in next.config.ts.
      deployFiles:
        - out/~

      # .next/cache preserves incremental compilation
      # state across builds — significantly speeds up
      # subsequent deployments.
      cache:
        - node_modules
        - .next/cache

    run:
      # Nginx serves the compiled assets — no Node.js
      # at runtime.
      base: static
      # Built-in SPA fallback serves /index.html for all
      # unmatched routes — no custom routing config needed
      # for Next.js static export.

  - setup: dev
    build:
      base: nodejs@22
      os: ubuntu
      buildCommands:
        # npm install (not ci) — lock file may not exist
        # yet in a fresh dev workspace.
        - npm install
      # Deploy the full working tree so the developer has
      # source code and node_modules ready via SSH.
      deployFiles: ./
      cache:
        - node_modules

    run:
      # Node.js at runtime so the developer can run
      # 'npm run dev' or any other tooling via SSH.
      base: nodejs@22
      os: ubuntu
      # Keep the container alive — developer drives via
      # SSH, starting their own dev server manually.
      start: zsc noop --silent
```

### 2. Enabling static export in `next.config.ts`

Next.js must be configured to produce a static export — this outputs plain HTML/CSS/JS into `out/` instead of a server bundle:

```ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  output: 'export',
}

export default nextConfig
```

### 3. Reading build-time environment variables

In static deployments there is no runtime process — all configuration must be injected at build time. Next.js exposes variables prefixed with `NEXT_PUBLIC_` to client code during the build:

```tsx
// Replaced at build time — not available at runtime.
const appEnv = process.env.NEXT_PUBLIC_APP_ENV ?? 'development'
```

Set the variable in `build.envVariables` in `zerops.yaml` (or as a Zerops service environment variable with the `RUNTIME_` prefix to inject it at build time from the Zerops UI).

### 🎯 What's next?

**Deploy other environments** — Ready to scale? Deploy additional environments for different stages of your workflow:

- [AI Agent](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=ai-agent)
- [Remote (CDE)](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=remote-cde)
- [Local](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=local)
- [Stage](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=stage)
- [Highly-available Production](https://app.zerops.io/recipes/nextjs-static-hello-world.md?environment=highly-available-production)

## Knowledge Base

### Platform Reference

- [Routing & Domains](https://docs.zerops.io/features/access)
- [Scaling](https://docs.zerops.io/features/scaling)
- [Environment Variables](https://docs.zerops.io/features/env-variables)
- [CLI (zcli)](https://docs.zerops.io/references/cli)

### Service Type Reference

**Static**

- [Configuration](https://docs.zerops.io/static/overview#routing-configuration)
- [SEO Setup](https://docs.zerops.io/static/overview#seo-with-prerender)
- [Frameworks](https://docs.zerops.io/static/overview#framework-integration)

---

## Related Recipes

- [Next SSR Hello World](https://app.zerops.io/recipes/nextjs-ssr-hello-world.md)
- [Bun Hello World](https://app.zerops.io/recipes/bun-hello-world.md)
- [Go Hello World](https://app.zerops.io/recipes/go-hello-world.md)
- [Zerops showcase](https://app.zerops.io/recipes/zerops-showcase.md)

