This guide puts a website on your VPS with Nginx and a free Let's Encrypt certificate, so it opens with HTTPS and renews its certificate by itself. It works for a static site and, with one change, for an app such as Node.js, Python or a Docker container.
You need a domain name and a sudo user (see First steps on a new Linux VPS). The commands are for Ubuntu and Debian. Replace example.com with your domain and 203.0.113.10 with your server's IPv4 address from the control panel.
1. Point your domain to the VPS
At your domain's DNS provider, create these records:
| Name | Type | Value |
|---|---|---|
example.com (often written as @) | A | 203.0.113.10 |
www | A | 203.0.113.10 |
Only add AAAA records with your IPv6 address if IPv6 already works on the server (ping -6 -c 3 google.com, or see Configure IPv6). Let's Encrypt prefers IPv6 when an AAAA record exists, so a broken IPv6 setup makes the certificate request fail.
Using Cloudflare for DNS? Set both records to DNS only (grey cloud) until your certificate works. Afterwards you can turn the proxy on with the SSL/TLS mode Full (strict).
Check from your own computer that the name points to your server. This can take from a few minutes to a few hours:
nslookup example.com 2. Install Nginx and open the web ports
sudo apt update
sudo apt install -y nginx
sudo ufw allow 80,443/tcp Open http://203.0.113.10 in your browser. You should see the Welcome to nginx page.
3. Create the site
Make a folder for your files that your own user can write to, with a test page:
sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com
echo '<h1>It works</h1>' > /var/www/example.com/index.html Create the Nginx configuration with sudo nano /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;
}
} Turn the site on, test the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx nginx -t must say syntax is ok and test is successful. Now http://example.com shows It works.
4. Get a free SSL certificate
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com Certbot asks for an email address and for you to accept the Let's Encrypt terms. It then gets the certificate and adds the HTTPS settings to your Nginx file. If it asks whether to redirect HTTP to HTTPS, choose the redirect. Open https://example.com to check.
5. Check that renewal works
Let's Encrypt certificates are short-lived, and Certbot renews them automatically in the background. Test the renewal once:
sudo certbot renew --dry-run If this ends with Congratulations, all simulated renewals succeeded, you don't need to do anything else.
6. Upload your website
Copy your files from your own computer to the server, for example with rsync (or scp, or an SFTP program such as FileZilla or WinSCP):
rsync -av ./my-site/ [email protected]:/var/www/example.com/ Running an app instead of static files
If your site is an app that listens on a local port (for example a Node.js or Python app on port 3000, or a Docker container published on 127.0.0.1:3000), let Nginx pass the requests to it. In step 3, replace the root, index and location lines with:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
} Then continue with nginx -t and Certbot as above. To keep the app itself running after a crash or reboot, see Keep an app or bot running 24/7.
Something not working?
- Certbot fails with a timeout or "unauthorized": check that
nslookup example.comshows your server's IP, that ports 80 and 443 are open (sudo ufw status), and the IPv6 and Cloudflare notes in step 1. - You still see "Welcome to nginx": you opened the IP address instead of the domain, or the domain doesn't point to the server yet.
- 502 Bad Gateway: the app behind
proxy_passisn't running or listens on a different port. - 403 Forbidden: there is no
index.htmlin the folder. - See the exact error:
sudo tail -n 50 /var/log/nginx/error.log
Last updated 2026-11-08. Need help? Open a ticket – our team answers 24/7.