This guide uses Ubuntu or Debian and the example domain example.com. Replace it with yours.
1. Point your domain to the VPS
At your domain provider, create two A records with your VPS IP address:
| Name | Type | Value |
|---|---|---|
@ | A | YOUR_SERVER_IP |
www | A | YOUR_SERVER_IP |
DNS changes can take a few minutes to a few hours.
2. Install Nginx
apt update
apt install -y nginx
If you use the UFW firewall, open the web ports:
ufw allow 'Nginx Full'
Open http://YOUR_SERVER_IP in a browser: you should see the Nginx welcome page.
3. Add your site
Put your website files in a folder:
mkdir -p /var/www/example.com
nano /var/www/example.com/index.html
Create the site config:
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;
}
Turn it on and reload:
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginx
4. Get a free SSL certificate
apt install -y certbot python3-certbot-nginx
certbot --nginx -d example.com -d www.example.com
Certbot asks for your email, gets the certificate and updates your Nginx config to use HTTPS. It also renews the certificate automatically. Test the renewal:
certbot renew --dry-run
Your site is now live on https://example.com.
Running an app instead of static files?
For Node.js, Python and similar apps, run the app on a local port (for example 3000) and replace the root lines with:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}