ShopYour purchases
Login

All articles

Setting up your product on a VPS

Learn how to deploy and host your product on your VPS server on your own domain.

Setting up your product on a VPS

Here's the quickest way to get your Next.js 14 application running on an Ubuntu VPS:

1

Install Node.js

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

2

Get Your Code and Install Dependencies

git clone your-repository-url
cd your-project-directory
npm install

3

Build and Start

npm run build
npm start

That's it! Your Next.js app should now be running on port 3000. You can access it at http://your-server-ip:3000

Note: To keep the app running after you close your terminal, you can use: nohup npm start &

Using Your Own Domain

To use your own domain with your Next.js app:

1

Add DNS Records

Go to your domain registrar (e.g., GoDaddy, Cloudflare, Namecheap) and add these records:

Type: A Record
Name: @ (or your subdomain)
Value: Your-VPS-IP-Address
TTL: 3600 (or automatic)

2

Install Nginx

sudo apt install nginx -y
sudo systemctl start nginx

3

Create Nginx Config

Ensure to change the yourdomain.com to your own domain:

sudo nano /etc/nginx/sites-available/nextjs

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

4

Enable the Config

sudo ln -s /etc/nginx/sites-available/nextjs /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Your Next.js app should now be accessible at yourdomain.com. DNS changes can take up to 48 hours to propagate, but usually only take a few minutes.

Thank you to ohwinterr for contributing to this article

Join the community

Talk to our community or create a ticket on our Discord server

Let's supercharge your online visibility

Logo

© 2024 Buzz Development. All Rights Reserved.