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.
ssh root@your-server-ipIf it’s your first time, update the server:
sudo apt update && sudo apt upgrade -yStep 2: Install Nginx
Run:
sudo apt install nginx -yCheck if it’s running:
systemctl status nginxYou should see something like:
Active: active (running)To view your default site, visit:
http://your-server-ipSee Also: How to Automate Deployment Pipelines with Bitbucket Pipelines (Complete Guide)
Step 3: Set Up Your Website Directory
Create a directory for your site:
sudo mkdir -p /var/www/mywebsite.com/htmlAssign permissions:
sudo chown -R $USER:$USER /var/www/mywebsite.com/html
sudo chmod -R 755 /var/wwwCreate an index.html file:
echo "<h1>Hello from Nginx VPS Hosting!</h1>" > /var/www/mywebsite.com/html/index.htmlSee Also: How to Host a Website with cPanel (Step-by-Step Guide)
Step 4: Configure the Nginx Server Block
Create a new config file:
sudo nano /etc/nginx/sites-available/mywebsite.comAdd this:
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:
sudo ln -s /etc/nginx/sites-available/mywebsite.com /etc/nginx/sites-enabled/Test and reload:
sudo nginx -t
sudo systemctl reload nginxStep 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):
sudo apt install certbot python3-certbot-nginx -yThen run:
sudo certbot --nginx -d mywebsite.com -d www.mywebsite.comCertbot automatically updates your Nginx configuration for HTTPS.
Step 7: Manage and Maintain
Check Nginx status:
sudo systemctl status nginxRestart or reload after changes:
sudo systemctl reload nginxRenew SSL automatically:
sudo systemctl enable certbot.timerBonus: 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.

