How I hosted NextJs on EC2
NextJs is great and provides you with a one-stop comprehensive solution for all your needs. Self-hosting NextJs for the first time can be burdensome, but I’m here to help. We’ll learn how to host NextJs on EC2 to control our hosting environment, so we won’t get shocked when those unexpected Vercel bill comes knocking.
Self-hosting on EC2 not only saves you from unexpected bills but can also be a good exercise to understand what is going on under the hood.
Setting Up EC2
The first step to host NextJs on EC2 is to setup and configure your EC2 environment properly, follow these steps carefully as some settings are notorious for changing after an instance is created.
Step 1
First, let’s login to AWS Console and navigate to “Launch an Instance”. You could come here by searching EC2. Then navigate to EC2 > Instances > Launch instances.
Step 2
Now select the instance type and the Linux image you want, I am choosing Amazon Linux 2023 and going with a t2.micro. You can choose any size you want, but consider choosing the Amazon Linux image as that is the image this tutorial will follow.