Home / Guides / Host a website with nginx
Guide

Host a website on a VPS with nginx and HTTPS.

This guide takes a fresh Ubuntu 24.04 VPS to a working HTTPS website. It works on any plan from BASE up.

Before you start

1. Install nginx

Install and start
sudo apt update
sudo apt install -y nginx
sudo systemctl enable --now nginx
curl -I http://127.0.0.1

2. Open the web ports

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

3. Create the site

Folder and test page
sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com
echo '<h1>It works</h1>' > /var/www/example.com/html/index.html
/etc/nginx/sites-available/example.com
sudo tee /etc/nginx/sites-available/example.com >/dev/null <<'EOF'
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.html;
    server_tokens off;
    location / { try_files $uri $uri/ =404; }
}
EOF
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

4. Enable HTTPS

Certbot gets a free certificate and renews it automatically.

Certbot
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot renew --dry-run

5. Add security headers

Inside the server block
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy no-referrer-when-downgrade always;

6. Keep it healthy

For a site that should hide its origin, read hide your origin IP.

  • Turn on automatic security updates.
  • Read logs with sudo tail -f /var/log/nginx/error.log.
  • Back up your site files off the server.
FAQ

Common questions

Which plan do I need for a website?

BASE is enough for a small static site. A CMS such as WordPress is more comfortable on CORE. See VPS plans.

Do I need a domain?

You can serve by IP, but HTTPS certificates need a domain name.

Is the certificate free?

Let's Encrypt certificates via Certbot are free and renew automatically.

Keep reading

Related pages

Anonymous offshore

How to host a website anonymously offshore: choose a jurisdiction, pay in crypto, deploy with nginx and HTTPS, and keep your identity out of the site.

Read more →

Hide your origin IP

Keep your web server IP out of public DNS: use a reverse proxy or CDN in front, lock the origin firewall and avoid leaks. Copy-and-paste commands.

Read more →

VPS hardening checklist: secure a new Linux server in 15 minutes

A practical checklist for a new Linux VPS: SSH keys, a non-root user, firewall, automatic updates and backups, with the commands.

Read more →

Docker Compose on a VPS

Install Docker and Docker Compose on a VPS, run an app, set restart policies and keep ports safe. Copy-and-paste commands for Ubuntu 24.04.

Read more →

Order a VPS paid in crypto.

Open the configurator