How to self-host a Next.js app on a VPS and escape Vercel's rising costs
A developer describes migrating Next.js projects from Vercel to a self-managed VPS after finding that costs climbed with traffic and serverless function usage. The approach uses a multi-stage Docker build with Next.js's standalone output mode, shrinking the production image from roughly 1 GB to around 200 MB. The final container runs as a non-root user, and static assets must be manually copied alongside the standalone server.js file or the app will load without CSS or images. Environment variables require careful handling: NEXT_PUBLIC_ values must be baked in at build time as Docker build arguments, while server-side secrets are injected at runtime via an env file. The author maintains a git-push-to-deploy workflow but retains full control over infrastructure costs and configuration.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in