How to Host a Website on a VPS with Nginx

Web Hosting 3 min read Updated June 2026

Nginx is a fast, lightweight web server used to serve websites and web applications. This guide walks you through installing Nginx and serving your first website on a cloud server running Ubuntu 22.04.

Prerequisites

Step 1: Update Your Server

apt update && apt upgrade -y

Step 2: Install Nginx

apt install nginx -y

Start and enable Nginx so it runs automatically on boot:

systemctl start nginx
systemctl enable nginx

Verify it's running:

systemctl status nginx

You should see active (running) in green.

Step 3: Allow HTTP Traffic Through the Firewall

If you have UFW (Ubuntu's firewall) enabled:

ufw allow 'Nginx Full'

This opens both port 80 (HTTP) and port 443 (HTTPS).

Step 4: Test the Default Page

Open a browser and go to:

http://YOUR_SERVER_IP

You should see the Nginx Welcome Page. Your server is working.

Step 5: Upload Your Website Files

Your website files go in /var/www/. Create a directory for your site:

mkdir -p /var/www/mywebsite

Upload your HTML/CSS/JS files using SCP from your local machine:

scp -r ./my-site/* root@YOUR_SERVER_IP:/var/www/mywebsite/

Or create a simple test page directly on the server:

echo "<h1>Hello from my cloud server!</h1>" > /var/www/mywebsite/index.html

Step 6: Configure a Server Block (Virtual Host)

A server block tells Nginx which files to serve and for which domain. Create a config file:

nano /etc/nginx/sites-available/mywebsite

Paste the following (replace yourdomain.com and the file path as needed):

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

    server_name yourdomain.com www.yourdomain.com;
    root /var/www/mywebsite;
    index index.html index.htm;

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

Save and exit (Ctrl+X, then Y, then Enter).

Step 7: Enable the Site

Link the config to the sites-enabled directory:

ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/

Test the configuration for syntax errors:

nginx -t

If you see syntax is ok, reload Nginx:

systemctl reload nginx

Step 8: Visit Your Website

If you've pointed a domain to your server IP, visit:

http://yourdomain.com

Otherwise, visit:

http://YOUR_SERVER_IP

Your website is now live!

Next, secure it with HTTPS for a free SSL certificate, or install WordPress if you want a CMS instead of static files.


Questions? Email us at [email protected] - we reply in under 2 hours, 7 days a week.

Top up in crypto.
Be root in a minute.

No cards. No KYC. Uninterrupted service since 2014. For people who'd rather not explain why they need a server.

Deploy a server →