Back to Blog

How to Host a Website on a VPS

How to Host a Website on a VPS
Command of the Day
curl -I http://localhost

What it does: Sends an HTTP HEAD request to test if the local web server is responding properly with HTTP status codes and headers.

Hosting your website on a Virtual Private Server (VPS) gives you complete control over web server software, caching engines, PHP configurations, and system resources—far surpassing the strict limitations of shared hosting.

In this tutorial, you will learn how to deploy a live website on your RivinCloud VPS using Nginx, custom domain mapping, and automated SSL encryption.


1. Prerequisites

Before starting, ensure you have:

  1. A Linux VPS (Ubuntu 22.04 or 24.04 recommended) from RivinCloud.
  2. A registered domain name (e.g., example.com).
  3. Root or sudo administrative access.

2. Step 1: Point Your Domain DNS to Your VPS IP

Log into your domain registrar (such as Cloudflare, Namecheap, or GoDaddy) and configure DNS records:

  • Type: A Record | Host: @ | Value: YOUR_VPS_PUBLIC_IP
  • Type: A Record | Host: www | Value: YOUR_VPS_PUBLIC_IP

(DNS changes typically propagate within 5 to 30 minutes).


3. Step 2: Install the Nginx Web Server

Nginx is the industry standard for high-concurrency, lightweight web serving:

sudo apt update
sudo apt install nginx ufw -y

# Allow Web Traffic in Firewall
sudo ufw allow 'Nginx Full'
sudo ufw enable

Test your web server by running:

curl -I http://localhost

You should see HTTP/1.1 200 OK and Server: nginx.


4. Step 3: Create Website Directory Structure

Create a dedicated web root directory for your website:

sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com

Create a sample index.html file:

nano /var/www/example.com/html/index.html

Add the following HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome to My Website</title>
    <style>body { font-family: sans-serif; text-align: center; padding: 50px; background: #0f172a; color: #f8fafc; }</style>
</head>
<body>
    <h1>🚀 Welcome to My Website Hosted on RivinCloud VPS!</h1>
    <p>Nginx web server is configured and running smoothly.</p>
</body>
</html>

5. Step 4: Configure Nginx Server Block (Virtual Host)

Create a new server block configuration file:

sudo nano /etc/nginx/sites-available/example.com

Paste the following configuration:

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;
}

Enable the server block by creating a symbolic link to sites-enabled:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Test syntax and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

6. Step 5: Secure with Free Let's Encrypt SSL/TLS

Install Certbot to enable HTTPS encryption:

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com

Follow the prompts to enter your email and agree to the terms. Certbot will automatically rewrite your Nginx configuration with SSL directives and configure automatic renewal timers!


Common Mistakes

  • Testing SSL before DNS propagates: Running Certbot before your DNS A record points to your VPS IP will cause Let's Encrypt ACME challenge verification to fail.
  • Incorrect file permissions: If /var/www/ permissions are set incorrectly, Nginx will return a 403 Forbidden error.

Troubleshooting

  • 502 Bad Gateway: If proxying to Node.js or PHP-FPM, verify that the backend daemon is running (systemctl status php8.2-fpm).
  • 404 Not Found: Verify that the root path in your Nginx config matches your actual folder location.

Best Practices

  • Enable Gzip compression in /etc/nginx/nginx.conf to speed up asset delivery.
  • Set up automated daily database and web root backups.

Frequently Asked Questions

Can I host multiple websites on the same VPS?

Yes! You can create separate server block configuration files in /etc/nginx/sites-available/ for as many domains and subdomains as your server resources can handle.


Conclusion

Deploying your website on a RivinCloud VPS gives you maximum speed, freedom, and scalability. Enjoy full control over your hosting stack!