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.
- 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
buildscript, 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.
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 saysnpm ciCreate the production buildnpm run buildStart it (port 3000)npm startKnow how the app will start
The standard build reads
next.configand picks one of three ways to run your app. By default it usesnext starton port 3000.With
output: "standalone"it starts the standalone server. Withoutput: "export"it serves the static files inout.next.config.mjs, if you want the standalone server/** @type {import('next').NextConfig} */ const nextConfig = { output: "standalone", // optional }; export default nextConfig;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,CREDENTIALorDATABASE_URLis not passed to the build.Which Next.js values reach the build in the standard build. App Router: render a page for each requestexport const dynamic = "force-dynamic";Connect your server
In the dashboard, open
Servers, pressAdd serverand chooseRun 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-pagerPrefer not to use a terminal? The connect screen also offers a password or SSH key login, and an AWS account connection for EC2.
Import the project and press Deploy
Open
Apps, pressDeploy appand import the repository fromGitHub. You can also paste a publicGit URLor useUpload.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. 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 theEnvironmenttab and pressSave 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
Liveand your pages load, including one that is rendered on the server. - Public values show correctly in the browser.
- The
Logstab shows no repeating runtime errors.
curl -I https://shop.example.comShould 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.
| Topic | Your VPS | Your Cloudflare account |
|---|---|---|
| How it runs | A Next.js server or static files in Docker | A Cloudflare Worker, through the OpenNext adapter |
| Next.js version | Your project's version, built with Node.js 20 | Next.js 15 or newer |
| Databases | Connect as you normally would | Direct TCP drivers need Hyperdrive or another driver |
| New releases | Dashboard, or git push with the GitHub app | Redeploy from the dashboard |
| Cost of running | Your server bill | Cloudflare'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.
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.
Open the app, go to
Domains, pressAdd domainand type the name withouthttps://.At your DNS provider, add the
Arecord the dashboard shows: the name (@for the root domain) and your server's IP address.Opslin checks every minute, and
Verify domainchecks now. It usually takes under 10 minutes.Opslin then requests a free Let's Encrypt certificate. Ports 80 and 443 must be open.
Retry HTTPStries again.
dig +short shop.example.comCustom 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.
| Plan | Free | Starter | Pro | Business |
|---|---|---|---|---|
| Rollback | Limited | Last release | Any release | Any 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
TOKENorSECRET. - Fix
- Set it in the
Environmenttab, rename it if needed, and pressSave 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 serverfree -hNext.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 tobuildand 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
Dockerfilethat starts your server, listening on0.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'sSettings.
Required environment variable is missing
- What it means
- The app started without a value it needs.
- Fix
- Add it in the app's
Environmenttab and pressSave 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