Hosting Next js application using caddy

Get 200$ in Digital Ocean and Get 100$ in Vultr

make sure you use ubuntu server and once you logged in you can follow following commands.

Install caddy

curl 5f5.in/caddy -Ls | bash -

Install node using NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc
nvm install node
node --version

Clone Next js sample app and setup

git clone https://github.com/fluxxset/Sample_next_js.git  /var/www/Sample_next_js
cd /var/www/Sample_next_js/sample
npm install 
npm install -g pm2
npm run build
pm2 start npm --name "sample" -- start
pm2 ls

test if app is working on port 3000

Configure Caddy

Update /etc/caddy/Caddyfile:

nano /etc/caddy/Caddyfile

Add the following:

next.1yt.in {

  reverse_proxy http://127.0.0.1:3000
    
}

Finally, restart and enable services:

# Reload systemd daemon
sudo systemctl daemon-reload

# Enable  service 
sudo systemctl enable react  

# Start 
sudo systemctl start react

# Restart Caddy 
sudo service caddy restart

Now, go to your browser, type the Domain , and you should see your Nextjs website running.