Vercel မသုံးဘဲ ကိုယ့် server၊ Kubernetes သို့မဟုတ် cloud container service ပေါ်တင်ချင်တာလည်း ဖြစ်နိုင်ပါတယ်။ Self-hosting က လွတ်လပ်မှုပိုပေးပေမယ့် reverse proxy၊ process restart၊ cache coordination နဲ့ security patch တို့ကို ကိုယ်တိုင်တာဝန်ယူရပါတယ်။
နားလည်ထားရမယ့် အချက်
next.config.ts မှ output: standalone ဖွင့်ရင် runtime အတွက်လိုအပ်တဲ့ file များကို သီးခြားထုတ်ပေးပါတယ်။ Multi-stage Docker build က dependency install၊ build နဲ့ runtime ကိုခွဲပြီး final image သေးစေပါတယ်။ Production မှာ Next.js server ကို internet ဆီတိုက်ရိုက်မဖွင့်ဘဲ nginx သို့မဟုတ် cloud load balancer နောက်ထားဖို့ official guide ကအကြံပြုပါတယ်။ Multiple instance သုံးရင် cache နဲ့ invalidation coordination ကိုလည်း စီစဉ်ရပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
# next.config.ts တွင် output: "standalone" ထည့်ပါ
FROM node:22-alpine AS builder
WORKDIR /app
COPY . .
RUN corepack enable && pnpm install --frozen-lockfile
RUN pnpm build
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
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"]Code က ဘယ်လိုအလုပ်လုပ်သလဲ
Builder stage က app ကို build လုပ်ပြီး runner stage က standalone output နဲ့ public assets ပဲယူပါတယ်။ Container က port 3000 မှာ server.js run ပါတယ်။ Database နဲ့ uploads ကို container filesystem ထဲ permanent မသိမ်းပါနဲ့။
Standalone Next.js server ပါသော production Docker image တည်ဆောက်နိုင်မည်။၅ မိနစ် စမ်းကြည့်
Docker health check၊ non-root user နဲ့ reverse proxy HTTPS ပါဝင်သော deployment diagram တစ်ခုရေးပါ။
Next.js — Self-Hosting — Next.js