Deploy a Next.js app to your own VPS, with HTTPS, logs and rollback.

Put your Next.js project on GitHub, connect your VPS to Opslin, add your environment variables and press Deploy. The standard build runs your build script with Node.js 20 in Docker on your server, then starts the app and checks it before it goes live.

Last checked 29 November 2026

Runs as
next start, standalone or static export
Node.js version
20 in the standard build
Port
3000
Change a NEXT_PUBLIC_ value
Save and redeploy

Who is this guide for?

You have a Next.js app, with server rendering, API routes or a static export, and you want to self-host it on a Linux server you control.

What you need

  • A Linux server you control, with root or sudo: Ubuntu, Debian, Fedora, Alpine or Arch, on 64-bit x86 or ARM.
  • At least 1.5 GB of free disk to install the agent. 5 GB or more is comfortable.
  • About 1 GB of memory or more. Smaller servers may run out of memory during a build.
  • Outbound HTTPS (port 443). Open inbound ports 80 and 443 so visitors and SSL certificates can reach your app.
  • A Next.js project with a build script, in GitHub, at a public Git address, or as a folder or ZIP (up to 500 MB).
  • Memory to spare: building Next.js on a small server can run out of memory.
  • An Opslin account with a verified email. The Free plan covers 1 server and 2 apps.

How do I deploy Next.js on a VPS?

You do not have to change your config to deploy.

  1. Check the production build on your computer

    Run the production build from a clean install and fix any error first. Keep secrets out of the repository.

    Install exactly what the lockfile says
    npm ci
    Create the production build
    npm run build
    Start it (port 3000)
    npm start
  2. Know how the app will start

    The standard build reads next.config and picks one of three ways to run your app. By default it uses next start on port 3000.

    With output: "standalone" it starts the standalone server. With output: "export" it serves the static files in out.

    next.config.mjs, if you want the standalone server
    /** @type {import('next').NextConfig} */
    const nextConfig = {
      output: "standalone", // optional
    };
    
    export default nextConfig;
  3. Sort your environment variables

    Names that start with NEXT_PUBLIC_ are written into the browser code during the build. Add them before you deploy, and treat them as visible to everyone.

    The standard build does not pass your other variables to next build; the running app gets them. A page that reads your database during the build should render at request time instead.

    As a safeguard, a public name that contains SECRET, TOKEN, PASSWORD, PRIVATE, CREDENTIAL or DATABASE_URL is not passed to the build.

    Which Next.js values reach the build in the standard build.
    App Router: render a page for each request
    export const dynamic = "force-dynamic";
  4. Connect your server

    In the dashboard, open Servers, press Add server and choose Run one command. Copy the command it shows, open a terminal on your server and paste it.

    The installer needs administrator rights. If you do not log in as root, it must run with sudo; choose your provider on that screen to get the right command.

    It installs Docker if needed and starts the Opslin agent, which connects out to Opslin. If the terminal prints a link to verify the server, open it while signed in. The link works for 1 hour.

    Choose a method, then run the command your dashboard shows.
    Check the agent on your server (systemd)
    sudo systemctl status opslin-agent --no-pager

    Prefer not to use a terminal? The connect screen also offers a password or SSH key login, and an AWS account connection for EC2.

  5. Import the project and press Deploy

    Open Apps, press Deploy app and import the repository from GitHub. You can also paste a public Git URL or use Upload.

    Name the project, pick your server, add your variables and press Deploy. The standard build uses Node.js 20 and the package manager that matches your lockfile.

    Name the project, pick your server and press Deploy.
  6. Follow the release

    Your server builds the app, starts the new version and runs a health check. Visitors move to it only after the check passes.

    To change a NEXT_PUBLIC_ value later, edit it in the Environment tab and press Save and redeploy, so the app is built again.

    The new version takes traffic only after its health check passes.

How do I know it worked?

  • The app shows Live and your pages load, including one that is rendered on the server.
  • Public values show correctly in the browser.
  • The Logs tab shows no repeating runtime errors.
Check the response (use your app's address)
curl -I https://shop.example.com

Should I run Next.js on a VPS or on Cloudflare?

Use a VPS for a long-running Next.js server and direct database connections. Use Cloudflare when you want no server and your app fits a Worker.

Next.js on your VPS and on your Cloudflare account with Opslin
TopicYour VPSYour Cloudflare account
How it runsA Next.js server or static files in DockerA Cloudflare Worker, through the OpenNext adapter
Next.js versionYour project's version, built with Node.js 20Next.js 15 or newer
DatabasesConnect as you normally wouldDirect TCP drivers need Hyperdrive or another driver
New releasesDashboard, or git push with the GitHub appRedeploy from the dashboard
Cost of runningYour server billCloudflare's plan; the free plan has limits

Read the Cloudflare hosting guide for the second option.

Where do I see Next.js logs?

In the app's Logs tab: switch between runtime and build output, search, filter by level and download.

Runtime and build output, with search and download.

How do I add my own domain with HTTPS?

Add the domain in the app, create one A record at your domain provider and let Opslin check it.

  1. Open the app, go to Domains, press Add domain and type the name without https://.

  2. At your DNS provider, add the A record the dashboard shows: the name (@ for the root domain) and your server's IP address.

  3. Opslin checks every minute, and Verify domain checks now. It usually takes under 10 minutes.

  4. Opslin then requests a free Let's Encrypt certificate. Ports 80 and 443 must be open. Retry HTTPS tries again.

One A record at your domain provider, then Opslin checks it.
See which IP your domain points to
dig +short shop.example.com

Custom domains on server apps need the Starter plan or higher. The Free plan gives each app a temporary Opslin address with SSL. Compare plans.

How do I roll back a bad release?

Open the app's Deployments tab, press Roll back next to an earlier successful release and confirm.

Opslin deploys that version again and re-applies your domain. The release you replaced stays in the history. Rolling back changes your code, not the data or structure of your database.

An earlier successful release can be deployed again.
Rollback by plan
PlanFreeStarterProBusiness
RollbackLimitedLast releaseAny releaseAny release

What can go wrong, and how do I fix it?

  • A NEXT_PUBLIC_ value is missing or old

    What it means
    It was added after the build, or its name contains a word such as TOKEN or SECRET.
    Fix
    Set it in the Environment tab, rename it if needed, and press Save and redeploy.
  • The build fails because it cannot reach the database

    What it means
    A page reads data during next build, and the standard build does not receive server-only variables.
    Fix
    Render that page at request time, for example with export const dynamic = "force-dynamic" in the App Router.
  • Container ran out of memory

    What it means
    The build or the app was stopped because the server did not have enough memory.
    Fix
    Free memory on the server or use one with more. Opslin builds on your server, so build size matters.
    See memory on the server
    free -h
  • Next.js TypeScript type check failed

    What it means
    Strict type checking is switched on with OPSLIN_NEXT_STRICT_TYPECHECK.
    Fix
    Fix the reported type error, or remove that variable to go back to the default.
  • Build command failed

    What it means
    The code was fetched, but installing packages or building ended with an error.
    Fix
    Open Logs, switch to build and fix the first error. Run the same build on a clean copy on your computer, then commit and push.
  • My custom server is not used

    What it means
    The standard build starts Next.js itself, not a custom server.js.
    Fix
    Add your own Dockerfile that starts your server, listening on 0.0.0.0.
  • Health check path returned 404

    What it means
    The app is running, but the health path you set does not return HTTP 200.
    Fix
    Set the path to a route that returns 200, such as /health, in the app's Settings.
  • Required environment variable is missing

    What it means
    The app started without a value it needs.
    Fix
    Add it in the app's Environment tab and press Save and redeploy.

What should I do next?

  • Deploy on every pushRelease each commit from your branch.GitHub guide
  • Host it without a serverPublish to your own Cloudflare account.Cloudflare guide
  • How releases workFrom your code to a live app, step by step.How it works

Questions people ask

Do I need output: "standalone" to self-host Next.js with Opslin?

No. Without it the standard build runs next start. Standalone and static export are also supported.

Do both the App Router and the Pages Router work?

Yes. Opslin runs your project's own build and starts the result.

Do TypeScript errors stop a deploy?

Not by default: the standard build ignores type errors while building. Add OPSLIN_NEXT_STRICT_TYPECHECK=true to make them fail the deploy, and run npx tsc --noEmit before you push.

Does Prisma work?

Opslin runs prisma generate during the build when it finds Prisma. Plan your schema changes as a separate step.

Do I need Nginx or PM2?

No. The app runs in a Docker container and Opslin sets up the web route.

Is it free to self-host Next.js this way?

The Free plan covers 1 server and 2 apps that you own. Custom domains on server apps need the Starter plan or higher. See pricing

Related pages

Try it with your own project.

  • Free plan: 1 server and 2 apps
  • Your server or your Cloudflare account