Cách mặc định: next build rồi next start chạy một Node server phục vụ cả static assets lẫn SSR/Route Handlers. Bạn đặt nó sau reverse proxy (Nginx) và cần cả thư mục .next lẫn toàn bộ node_modules.
Vấn đề: copy nguyên node_modules (hàng trăm MB) vào image thì nặng và chậm.
output: 'standalone' giải quyết: Next.js trace đồ thị dependency và chỉ đóng gói những file thực sự được dùng vào .next/standalone/ kèm một server.js chạy độc lập.
// next.config.js
module.exports = { output: 'standalone' }Lúc deploy chỉ cần .next/standalone, .next/static và public, rồi node server.js — không cần npm install ở runtime.
Lưu ý: standalone không tự copy public/ và .next/static — phải copy thủ công (Docker thường thêm 2 thư mục này). Image optimization cần cài sharp.