Next.js
/Advanced
Self Hosting
Definition
Deploying and managing a Next.js application on your own infrastructure (AWS EC2, DigitalOcean, custom servers) rather than relying on managed platforms like Vercel.
Explain Like I'm New
Vercel is a luxury hotel; they make your bed and cook your food, but it costs a premium. Self-hosting is buying land and building a house; it's much cheaper, but if the plumbing breaks, you have to fix it yourself.
Real World Example
A healthcare startup must comply with strict HIPAA regulations, requiring them to host the application on their own private, firewalled AWS servers, managing the Node.js process using PM2 or Docker.
Common Use Cases
- •Data compliance
- •Cost reduction at extreme scale
- •Custom infrastructure requirements
Terminal Output
bash / terminal
/*
Steps to Self-Host Next.js on a Linux Server (Ubuntu):
1. SSH into the server.
2. Clone the repository: `git clone ...`
3. Install dependencies: `npm install`
4. Build the project: `npm run build`
5. Start the process using a Process Manager (like PM2)
so it automatically restarts if the server crashes:
`pm2 start npm --name "next-app" -- run start`
6. Configure NGINX to reverse-proxy port 80 to port 3000.
*/
Interview Questions
basic
- What command is used to start a production Next.js server when self-hosting?
intermediate
- If you self-host Next.js on a single DigitalOcean droplet, what Vercel feature do you immediately lose?