C.W.K.
Stream
Lesson 02 of 08 · published

Self-Hosting

~22 min · self-host, next start, PM2

Level 0Curious
0 XP0/68 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

모든 framework feature 가 self-hosted 작동

Server Component, RSC streaming, ISR, Server Action, image/font optimization — 다 vanilla Node.js server 에서 next start 통해 돌아. 바뀌는 부분: SSL, process manager, CDN 본인이 운영.

Production server

npm run buildnpm run start. Default port 3000; -p 로 override. Server 가 default single-process; 살아있게 + scale 위해 process manager (PM2, systemd, launchd, Docker orchestrator).

Reverse proxy

TLS termination, request logging, gzip/brotli 위해 next start 앞에 nginx 또는 Caddy. Caddy 가 가장 단순 — TLS 자동.

Image optimization 이 sharp 필요

Self-hosted 에서 optimizer 가 내부적으로 sharp 사용. 명시적 install 해서 production 이 unoptimized image 로 fallback 안 하게.

Code

Build 와 run·bash
npm run build
npm install sharp                  # next/image optimization 위해
NODE_ENV=production npm run start  # default port 3000

# Custom port
NODE_ENV=production npm run start -- -p 8080
PM2 가 살아있게·bash
npm install -g pm2
pm2 start npm --name nextjs -- start
pm2 save
pm2 startup       # launchd / systemd integration 생성

pm2 status
pm2 logs nextjs
pm2 reload nextjs # zero-downtime restart
Caddy reverse proxy·text
# Caddyfile
myapp.com {
  reverse_proxy localhost:3000
}
# Caddy 가 Let's Encrypt 통해 HTTPS 자동 처리

External links

Exercise

Mac 또는 Linux box 에서 Next.js app 을 Caddy 뒤에 self-host. HTTPS 자동 작동, PM2 가 process kill 시 restart 하는지 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.