Getting started
How to host a website on a VPS with Nginx and free HTTPS
Install Nginx, publish a site, point your domain at it and add a free Let’s Encrypt certificate that renews itself.

This guide takes a fresh Ubuntu or Debian VPS to a website served over HTTPS, with a certificate that renews itself. It assumes you can log in over SSH with a sudo user and that you own a domain name. The examples use example.com and the address 203.0.113.10.
1. Point the domain at the server
In your DNS settings, create two records:
| Type | Name | Value |
|---|---|---|
| A | @ | 203.0.113.10 |
| A | www | 203.0.113.10 |
Do this first: the certificate step needs the domain to resolve. Details are in Point a domain name to your server.
2. Install Nginx
sudo apt update
sudo apt install -y nginx
If a firewall is active, open the web ports:
sudo ufw allow 80,443/tcp
Visit http://203.0.113.10 in a browser. The “Welcome to nginx” page means the server is answering.
3. Create the site
Make a directory for the files and put a first page in it:
sudo mkdir -p /var/www/example.com
echo '<h1>It works.</h1>' | sudo tee /var/www/example.com/index.html
Describe the site to Nginx in /etc/nginx/sites-available/example.com:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable it, test the configuration and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
http://example.com should now show your page.
4. Add HTTPS
Certbot requests a free certificate from Let’s Encrypt and edits the Nginx configuration for you:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Accept the terms. Certbot then asks for an email address: recent versions let you leave it empty, older ones (the one Ubuntu 24.04 installs, for example) need --register-unsafely-without-email at the end of the command to go without. Certbot adds the certificate, a redirect from HTTP to HTTPS, and a timer that renews the certificate before it expires. Check the renewal with:
sudo certbot renew --dry-run
5. Two settings worth adding
Inside the server block that listens on 443, compress text and let browsers cache static files:
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
location ~* \.(css|js|png|jpg|webp|avif|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public";
}
Run sudo nginx -t && sudo systemctl reload nginx after every change. nginx -t refuses a broken configuration before it can take the site down.
Serving an application instead of files
For a Node, Python or Go application listening on a local port, replace the location / block with a proxy, and remove the block for static files added in step 5: with it, Nginx would look for the application’s CSS and JavaScript on disk and answer 404.
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
Keep the application bound to 127.0.0.1 so that Nginx is the only way in.
When it does not work
- Certbot fails with a DNS or connection error: the domain does not point to this server yet, or port 80 is closed. Check with
dig +short example.com. - You still see the default page: the
server_namedoes not match the address you typed, or the site was not enabled. - 403 Forbidden: Nginx cannot read the files.
sudo chmod -R o+rX /var/www/example.comfixes the usual case. - What went wrong?
sudo tail /var/log/nginx/error.logsays so in one line.
Sources and further reading
Read nextTwo guides to follow this one.
All getting started guides
Getting startedVPS vs dedicated server: how to chooseShared hardware against a whole machine: performance, price, noisy neighbors, and the point where moving up pays off.
Getting startedHow to connect to a Windows RDP serverOpen a remote desktop session from Windows, macOS, Linux, iPhone or Android, and fix the usual connection errors.
Your own server, in a few minutes.
Cloud VPS from $3.99 a month: no email, no ID, crypto payment, root access in minutes.
- No KYCNo email, no ID
- No DMCANotices not acted on
- Crypto friendlyBTC, ETH, XMR, USDT, SOL
- UnmeteredOn every plan