One morning both of my sites, devoun.com and this one, returned an error page. The hosting plan had paused the account for going over its usage limits. Nothing was broken in the code. The sites were simply switched off until someone paid or waited.
For a company website, that is the wrong kind of risk. So I moved both sites to a single VPS I already had, running Docker. The move took a day, and the sites stay fast. Here is the setup and why each part is there.
The shape of it
Requests pass through three layers. Traefik handles HTTPS with free Let's Encrypt certificates, compression and the redirect from the bare domain to www. Behind it, nginx keeps a cache of rendered pages and build files. Behind that, each site runs as a Next.js standalone server in its own container.
A cache that works like a CDN
The part that keeps the sites fast is the nginx cache. Hashed build files under /_next/static never change, so they are cached for a year. Pages are cached for ten minutes and refreshed in the background, so visitors almost always get a cached copy. API routes and admin pages are never cached.
One detail matters with the App Router: Next.js fetches React Server Component payloads from the same URL as the HTML page. If the cache key ignores the RSC and Next-Router headers, a visitor can be served the wrong one and see raw data instead of a page. Including those headers in the key fixes it.
Deploy on push, without a CI service
A systemd timer runs every two minutes. It fetches the repository and, if main has a new commit, builds the new image and restarts the container. A failed build leaves the running site untouched, and a lock makes sure two deploys never overlap. After each deploy the page cache is emptied, so new content shows at once.
The same timer idea handles scheduled publishing. Blog posts with a future date are hidden at build time, and a weekday rebuild releases each one on its date. The build date is passed into Docker so it never reuses yesterday's build by mistake.
When self-hosting makes sense
- Your traffic is steady and you want a fixed monthly cost.
- You already run a server for other tools and can share it.
- You are comfortable owning updates, backups and monitoring, or have someone who is.
Managed platforms are still the right choice for many teams, especially early on or with very spiky traffic. The point is to choose on purpose, with a plan for what happens when the bill or the limits change.
I published the whole setup as an open-source template you can copy: nextjs-vps-starter on GitHub. If you want help moving a Next.js app to your own server, or making one hold up in production, that is the kind of work we do at Devoun.
Originally published on attarehman.com. I'm Atta Ur Rehman, founder of Devoun and a fractional CTO with 14+ years of experience.

