What You Need to Host a Static Website on Nginx
Learning how to host a static website on Nginx is the fastest way to get a site online on a VPS. A static site is just HTML, CSS, JavaScript, and images, with no database and no server-side code to run. Nginx serves those files directly from disk, which makes it fast, simple, and hard to break. This guide walks through installing Nginx on Ubuntu 24.04, creating a server block, uploading your files, and adding HTTPS.
You need a VPS with Ubuntu 24.04, a domain pointed at the server IP, and SSH access. If the server is brand new, run through the first 10 things to do after buying a VPS before hosting anything public, because a fresh server with default credentials is an easy target. A static site has a small attack surface, but the server underneath still needs updates, a firewall, and key-only SSH login.
Install Nginx and Create the Site Directory
Install Nginx from the Ubuntu repository and confirm it runs:
sudo apt update && sudo apt install nginx -y
sudo systemctl status nginx --no-pager
curl -I http://localhost
Next, create a directory for your site and a simple index page to test with:
sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com
cat > /var/www/example.com/index.html <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Example Site</title></head>
<body><h1>It works</h1></body>
</html>
EOF
The ownership change lets you upload files without using root for every edit. In production, the web server user www-data only needs read access to these files, so do not set permissions to 777. Files at 644 and directories at 755 are correct for a static site.
Create an Nginx Server Block for the Static Site
A Nginx server block tells Nginx which domain maps to which directory. Create the configuration file:
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location ~* .(css|js|png|jpg|jpeg|gif|svg|webp|ico)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
}
The root directive points at your files, and the Nginx root directive is the setting most beginners get wrong, usually by pointing it at the wrong directory or by forgetting that root inside a location overrides the server-level value. The try_files line serves the exact file if it exists, tries a directory index next, and returns 404 otherwise. The second location block adds browser caching headers for static assets, so repeat visitors do not re-download CSS and images on every page.
Enable the site and test the configuration:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
If you want the full background on this layout, the tutorial for setting up Nginx server blocks on Ubuntu 24.04 explains each directive and the sites-available pattern in detail. A static website on Ubuntu deployed this way is also a good base for later steps: the same server block can gain HTTPS, caching, and security headers without restructuring anything.
Upload Your Files and Add HTTPS
Upload your built site into /var/www/example.com with rsync or SFTP, replacing the test index page. Keep the structure flat and predictable: HTML at the top level, assets in subdirectories like css/, js/, and images/. Check the site in a browser before adding HTTPS, because a broken HTTP site will still be broken behind TLS, and debugging is easier without certificates in the way.
Once HTTP works, add HTTPS with Certbot:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
sudo systemctl status certbot.timer --no-pager
Certbot edits your server block to add the TLS listeners and a redirect from HTTP to HTTPS. The timer renews certificates automatically, so check that the timer is active rather than assuming renewals work. A detailed walkthrough for this step is the guide to installing a free Let’s Encrypt certificate on Nginx.
Updating the site later is just a file upload. Replace the files in /var/www/example.com, and visitors see the new version immediately, unless their browser cached the old assets for 30 days under the caching headers you set. When you push a changed stylesheet or script, change its filename or add a version query string so returning visitors fetch the new file instead of the cached one. If you use a build tool, it usually handles this fingerprinting for you. For a hand-written site, renaming style.css to style-v2.css and updating the HTML reference is enough. This simple workflow is why static sites stay popular: deploys are file copies, rollbacks are file copies in reverse, and there is no database migration to fear.
For a site that will grow into something dynamic later, this static setup is not wasted work. The server block, the TLS configuration, and the caching headers all carry over. If you later add an application behind Nginx, the beginner tutorial for Nginx reverse proxy setup shows how to proxy to it while keeping the static files served directly, which is the fastest arrangement for mixed sites.