This guide hosts a Next.js app on Amazon EC2 using the stock production server (next start via npm start) under PM2—no custom Express wrapper required.
What is Next.js on EC2 with next start?
After next build, next start serves the compiled app from .next. On Ubuntu EC2 you install Node, upload sources, build on the server, and let PM2 keep the process running.
When should you use this approach?
Prefer this path for most single-VM demos and small production apps. Use Next.js + Express on EC2 only when you need a custom Node HTTP layer in the same process. For scale and HTTPS, add an ALB, ACM, or CloudFront.
What you will build
Scaffold with create-next-app, add pm2.config.js, upload with FileZilla (no node_modules), then npm install, npm run build, and pm2 start pm2.config.js.
Why PM2?
Closing SSH would kill a foreground npm start. PM2 supervises the process, shows logs/status, and can restart the app after reboot when you run pm2 startup / pm2 save.
Stock production path.
Build, then npm start (next start). That matches how Next.js expects a single Node host to run.
Single process first.
The sample config uses one fork worker. Enabling PM2 cluster with many instances on a small VM can starve CPU/RAM—measure before scaling workers.
Install and build on EC2.
Skip uploading node_modules and usually .next; regenerate them on the instance for the correct OS/CPU.
Reference
Core Concepts
Terms you will use in this deploy:
Concept
Meaning
create-next-app
Official scaffold for a new Next.js project
next build
Compiles the app into the .next production output
next start / npm start
Serves the production build (no custom Express file)
Most failures are a missing build, wrong working directory, or an over-eager PM2 cluster.
build
Started without npm run build
next start needs a successful production compile. Build on EC2 before pm2 start.
cwd
Wrong directory for PM2
Run pm2 start pm2.config.js from the project root so npm start finds package.json.
cluster
Too many PM2 workers
instances: max on a tiny instance can thrash. Keep instances: 1 until you measure spare capacity.
npm
Uploaded laptop node_modules
Native modules can break across OS/CPU. Delete them and run a fresh npm install on EC2.
sg
Security group blocks HTTP
Allow inbound TCP 80 from your client (and 22 for SSH) or the browser will time out.
reboot
App gone after instance reboot
Use pm2 startup and pm2 save so PM2 restores the process after a reboot.
Remember
Key Takeaways
Path:next build then npm start via PM2—the stock Next production flow.
Install on EC2: skip uploading node_modules; rebuild .next on the server.
PM2: one fork worker first; add cluster workers only after load testing.
Express optional: use the Express guide only when you need a custom server.
One line: build on EC2, pm2 start runs next start, keep one process until you need more.
Frequently Asked Questions
After next build, npm start runs next start, which serves your production build. It is the standard way to run Next.js without a custom Express server.
PM2 keeps the Node process alive after you disconnect SSH, can restart on failure, and integrates with OS startup scripts so the app comes back after reboot.
Start with a single forked process. Running many clustered Node workers on a small VM can exhaust CPU and RAM; scale out or tune clustering after load testing.
Usually no. Upload source and lockfiles, then run npm install on the server so binaries match the instance architecture.
Only when you need a custom Node HTTP layer in the same process. Otherwise prefer next start. See the Next.js + Express on EC2 guide for that pattern.
Yes. next start serves the production output in .next. Without a successful build, the production server will not work correctly.