Cloud & DevOps•8 min read•0 views•

Why We Ditched Serverless: Self-Hosting Next.js on Hetzner VPS with Docker & Nginx

A practical guide to slashing your cloud hosting bills by 90% while getting dedicated CPU performance, zero cold starts, and automated SSL rollouts.

Abu Nayem

Abu Nayem

Full-Stack Developer & AI Specialist

Why We Ditched Serverless: Self-Hosting Next.js on Hetzner VPS with Docker & Nginx

1. The Hidden Costs & Cold Starts of Serverless

Serverless hosting platforms charge massive markups on bandwidth egress, function execution duration, and database connection limits. Furthermore, serverless functions suffer from 1-3 second cold starts when spun up after idle periods.

For $10/month on a dedicated Hetzner Cloud VPS (4 vCPUs, 8GB RAM, NVMe SSD), you get raw performance that handles over 250,000 daily requests with 0ms cold starts.

2. Next.js Standalone Docker Image (< 100MB)

By configuring `output: 'standalone'` in `next.config.mjs`, Next.js bundles only the required production files into an ultra-lean 90MB Alpine Docker image:

Dockerfile
FROM node:22-alpine AS base
WORKDIR /app
RUN apk add --no-cache libc6-compat

FROM base AS builder
COPY package.json package-lock.json* ./
RUN npm ci
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build

FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000

COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 3000
CMD ["node", "server.js"]

3. Nginx Reverse Proxy & Auto Let's Encrypt SSL

Configure Nginx to proxy incoming HTTPS requests to your Docker container port, apply gzip/Brotli compression, cache static assets, and automatically renew SSL certificates via Certbot cron jobs.

4. Automated GitHub Actions Zero-Downtime Deployment

With GitHub Actions, pushing to `main` triggers an SSH runner that pulls the new Docker image, runs health checks, and reloads Nginx with zero dropped connections.

Conclusion & Final Thoughts

Self-hosting on high-performance Linux VPS infrastructure gives growing startups immense cost savings, predictable billing, total data control, and unbeatable server response times.

Did you enjoy this article?

Give love to support more technical masterclasses & writing!

Tags:#Docker#Linux VPS#Hetzner#Nginx#Coolify#DevOps#Next.js
Abu Nayem

Abu Nayem

Full-Stack & AI Specialist

Abu Nayem manages cloud server architectures, container orchestration, and high-availability database deployments.

Book Strategy Call
Enjoyed this engineering guide?