CraftedTemplate
Blog How to Host a Website on an Nginx VPS (Complete Ubuntu Server Guide)

How to Host a Website on an Nginx VPS (Complete Ubuntu Server Guide)

11/2/2025 • Festus Ayomike
How to Host a Website on an Nginx VPS (Complete Ubuntu Server Guide)

If you’ve been hosting on managed platforms like Vercel or Netlify, you might wonder: What if I want full control of my hosting environment? That’s where a Virtual Private Server (VPS) comes in.

Hosting your website on a VPS with Nginx gives you flexibility, speed, and total control — ideal for developers or businesses who want to optimize performance or host multiple sites on one server.

In this guide, you’ll learn step-by-step how to set up Nginx on Ubuntu, configure domains, and deploy your website securely.

See Also: How to Set Up Continuous Deployment with GitLab CI/CD (Complete Beginner’s Tutorial)

What You’ll Learn

  • How to connect to a VPS via SSH
  • How to install and configure Nginx
  • How to set up your website files
  • How to manage domains and SSL certificates
  • How to restart, reload, and troubleshoot your server

Step 1: Connect to Your VPS

After purchasing a VPS from providers like DigitalOcean, Linode, or Vultr, connect to it via SSH.

Code · batchfile
ssh root@your-server-ip

If it’s your first time, update the server:

Code · batchfile
sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

Run:

Code · batchfile
sudo apt install nginx -y

Check if it’s running:

Code · batchfile
systemctl status nginx

You should see something like:

Code · batchfile
Active: active (running)

To view your default site, visit:

http://your-server-ip

See Also: How to Automate Deployment Pipelines with Bitbucket Pipelines (Complete Guide)

Step 3: Set Up Your Website Directory

Create a directory for your site:

Code · batchfile
sudo mkdir -p /var/www/mywebsite.com/html

Assign permissions:

Code · batchfile
sudo chown -R $USER:$USER /var/www/mywebsite.com/html
sudo chmod -R 755 /var/www

Create an index.html file:

Code · batchfile
echo "<h1>Hello from Nginx VPS Hosting!</h1>" > /var/www/mywebsite.com/html/index.html

See Also: How to Host a Website with cPanel (Step-by-Step Guide)

Step 4: Configure the Nginx Server Block

Create a new config file:

Code · batchfile
sudo nano /etc/nginx/sites-available/mywebsite.com

Add this:

Code · batchfile
server {
    listen 80;
    server_name mywebsite.com www.mywebsite.com;

    root /var/www/mywebsite.com/html;
    index index.html;

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

Enable it:

Code · batchfile
sudo ln -s /etc/nginx/sites-available/mywebsite.com /etc/nginx/sites-enabled/

Test and reload:

Code · batchfile
sudo nginx -t
sudo systemctl reload nginx

Step 5: Point Your Domain

Go to your domain registrar (e.g., Namecheap, GoDaddy) and add an A record:

  • Host: @
  • Value: your server IP

Wait for propagation (can take up to 1 hour).

Step 6: Enable SSL with Certbot

Install Certbot (Let’s Encrypt):

Code · batchfile
sudo apt install certbot python3-certbot-nginx -y

Then run:

Code · batchfile
sudo certbot --nginx -d mywebsite.com -d www.mywebsite.com

Certbot automatically updates your Nginx configuration for HTTPS.

Step 7: Manage and Maintain

Check Nginx status:

Code · batchfile
sudo systemctl status nginx

Restart or reload after changes:

Code · batchfile
sudo systemctl reload nginx

Renew SSL automatically:

Code · batchfile
sudo systemctl enable certbot.timer

Bonus: Host Multiple Websites

You can host multiple domains by repeating Steps 3–6 with separate config files and directories.

Conclusion

Hosting your website on an Nginx VPS gives you full control over performance, configuration, and security — without the limitations of shared hosting or managed platforms.

Next, we’ll build on this setup by adding a reverse proxy and SSL using Nginx and Certbot for a production-grade configuration.