Hosting a website on a VPS takes three things: a web server to serve your files, a domain pointing at your server's IP, and an HTTPS certificate. Nginx handles the first part easily, and certbot gets you a free Let’s Encrypt certificate. In this guide the site runs on Ubuntu 24.04 or Debian 12, with HTTPS set up automatically and renewing on its own. Your domain should already point to the server. If it doesn't yet, see how to point a domain to your VPS.

What you need

  • A VPS with a public IPv4 or IPv6 address and SSH access. See how to connect to a VPS over SSH.
  • A domain, for example example.com, with A or AAAA records pointing to your server.
  • Your site files: static HTML, CSS and JavaScript, or a built frontend.

Step 1. Install Nginx

Update the package list and install Nginx. It starts right away and listens on port 80.

sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx
sudo systemctl enable --now nginx
systemctl status nginx --no-pager

Open your server's IP in a browser. If you see the default Nginx welcome page, the web server is up. Your domain won't serve your site yet, because the directory with your files doesn't exist.

Step 2. Create the site directory and set permissions

Keep site files outside system directories, for example in /var/www/example.com/html. Create the directory, copy your files in and set the owner Nginx runs as.

sudo mkdir -p /var/www/example.com/html
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 755 /var/www/example.com
echo 'It works' | sudo tee /var/www/example.com/html/index.html

The www-data user can read the files, and only the owner can change them. If you upload the site over SFTP as your own user, either upload into a directory owned by www-data or share access through a separate group.

If your site is a Python, Node.js or Go app, Nginx usually runs as a reverse proxy instead. It accepts requests on ports 80 and 443 and hands them to your app on a local port with proxy_pass. For a plain static site, a directory of files is simpler and more reliable, so that's what this guide uses.

Step 3. Add a server block for your domain

A server block tells Nginx which domain maps to which directory. Create the config at /etc/nginx/sites-available/example.com.

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

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

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

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

Enable the site with a symlink in sites-enabled, test the syntax and reload Nginx. Always run nginx -t before a reload: if there's an error, it points to the line, and Nginx keeps running on the old config.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

Now open http://example.com. If you see your index.html, the site works over HTTP. Next up: HTTPS.

try_files checks, in order, whether a file exists at the requested path, then whether a directory with that name exists, and only then returns a 404. Want /about to serve about.html? Add $uri.html to the list: try_files $uri $uri.html $uri/ =404.

Step 4. Open ports 80 and 443 in the firewall

Let’s Encrypt verifies domain ownership over port 80, and visitors connect over port 443 for HTTPS. If ufw is enabled on the server, open both. Allow SSH first, or you'll lose access as soon as the firewall turns on.

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status

The Nginx Full profile opens 80 and 443. If your provider also has a firewall in its control panel, open the same ports there: those rules are independent of ufw, and the port has to be open in both places. You could run a site on port 80 alone without HTTPS, but you really shouldn't.

Step 5. Get a Let’s Encrypt SSL certificate

Install certbot and its Nginx plugin. The plugin edits your config for you: it adds a listener on port 443, the certificate paths and an HTTP-to-HTTPS redirect.

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

certbot asks for an email address for expiry notices and asks you to accept the terms. When it asks about redirecting HTTP to HTTPS, pick the redirect. Before you run it, make sure both example.com and www.example.com already point to the server's IP, or validation will fail.

certbot backs up the configs it changes and stores certificates in /etc/letsencrypt/live/example.com. Don't copy these files around by hand: certbot knows where to find them at renewal time.

Just testing the process? Add --staging. The Let’s Encrypt staging server doesn't issue trusted certificates, but it doesn't eat into your production rate limits either.

Step 6. Check automatic renewal

Let’s Encrypt certificates are short-lived. The certbot package installs a systemd timer that checks them and renews them a few weeks before they expire. Make sure the timer is active, then do a dry run of the renewal.

systemctl list-timers | grep certbot
sudo certbot renew --dry-run

If the dry run passes, the server will renew the certificate on its own. Nginx has to reload after a renewal, and the certbot plugin takes care of that automatically. To see the expiry date, run sudo certbot certificates.

Why bother? Browsers flag sites without HTTPS as not secure, and search engines treat encryption as a quality signal. Once the certificate is in place, open the site in a browser, check for the padlock and make sure the http URL redirects to https.

Troubleshooting

  • certbot fails domain validation. Check the A or AAAA record with dig +short example.com and make sure port 80 is open.
  • Nginx won't reload after an edit. Run sudo nginx -t and fix the line it reports.
  • The site loads by domain but not by IP, or the other way around. Check server_name and which server block comes first in sites-enabled.
  • You see old files. Clear your browser cache and confirm you uploaded to the right root directory.

Back up the config before any edit, for example with sudo cp /etc/nginx/sites-available/example.com /root/example.com.bak. If something breaks, you can roll back in a minute, even after certbot has modified the file.

Wrapping up

A website on a VPS comes down to Nginx, a directory of files, a server block for your domain and a Let’s Encrypt certificate. certbot issues the certificate and sets up HTTPS, and a systemd timer renews it without you lifting a finger. For a project with several services or a database, containers make life easier: see Docker on a VPS. Still choosing a server for your site? Read how to choose a VPS first, then compare plans in the VPS section. Updating a static site is just a matter of uploading new files to the root directory: Nginx serves them right away, no restart needed. Back up the site directory and configs regularly so you can recover from mistakes.