See all posts

Self-hosting Next.js

Neil Patrick D. Villanueva (@drxco)

Sun Apr 06 2025

If you have read online, Next.js is one of those frameworks that promises ease of use. Deploying it yourself, however, can be a bit tricky. One way to do it is through Vercel. Simply because Next.js was built by them. But if you want to self-host, you have to be a little more careful.

But how do we do it?

Docker is a great choice for self-hosting. You can containerize your application and run it on any machine that supports Docker. For the past two side projects, I've used Docker to deploy Next.js apps with minimal issues. But I'm not saying it is easy. I spend days and hours simply configuring my NGINX reverse proxy. And in addition to that, those SSL certificates are a pain.

But what I realized it that the key to self-hosting is ensuring your Dockerfile and compose files are properly configured with the right build commands and environment variables, and also making your life easier with bash scripts. Bash scripts are lifesavers.

Luckily, the Next.js team provides sufficient documentation and examples. One great resource is from Lee Rob with his next-self-host project. I recommend you look into this repository if you are considering self-hosting Next apps. I have used his project as a reference for my side projects, including this app, seenaa.

Why even self-host?

Well, one of the main reasons is cost, particularly if you have an existing server. You can avoid vendor lock-in and have full control of your deployment. Moreover, you have the freedom to fine-tune your server configurations to match your app's needs. This level of customization can be incredibly valuable as your project scales.

However, there are also some drawbacks. Self-hosting requires more technical expertise and ongoing maintenance compared to using a managed platform. You're responsible for everything from security to server updates. Moreover, you need to handle scaling and load balancing yourself, which can be complex. Despite these challenges, the benefits of self-hosting, like cost savings and control, often outweigh the costs, especially for projects that demand specific server configurations.

But for this side project, self-hosting is a must. I want full control of my deployment and server configurations. In addition, I do not need to provision extra services like PostgreSQL, I can use Docker Compose instead. This is more cost-effective and easier to manage for a small project. I hosted this application with a $1 /month VPS.

Also, this project is a good learning experience. It gives me an opportunity to refresh my knowledge of Docker and web server configurations. The learning curve can be steep, but the ability to control your deployment environment is worth the effort.

When should you self-host?

On the other hand, managed platforms like Vercel or Netlify are better suited for quick deployments where convenience outweighs customization. If your project doesn't require complex server setups and you prefer minimal maintenance, sticking with these services might be the smarter choice. Ultimately, the decision depends on your project's specific needs and your technical comfort level. For small projects or prototypes, managed platforms save time, but for production-grade applications with unique requirements, self-hosting provides the flexibility needed. Just weigh the trade-offs between control and convenience before making your decision. Especially with Next.js, self-hosting can be a viable option if you're comfortable with the additional setup and maintenance. It's particularly useful when you need custom server-side logic or specific optimizations that managed platforms might not support. Just ensure you're prepared to handle the infrastructure aspects before diving in.

Created with seenaa

seenaa
© 2025 seenaa. All rights reserved.
Self-hosting Next.js | drxco