Prerequisites
DNS records of the domain must be already configured to point to the VPS instance.
Note: These instructions are for Debian.
Install required applications
nginx
for web server and python3-certbot-nginx
for SSL certificate.
sudo apt update
sudo apt install nginx python3-certbot-nginx -y
Prepare Files
Lets say we have a file named index.html
with the contents as follows.
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>Hello from VPS</title>
</head>
<body>
<h1>Hello from VPS</h1>
</body>
</html>
Store the website content
Store the files inside of /var/www/mydomain.com
mkdir /var/www/mydomain.com
cp /path/to/index.html /var/www/mydomain.com
Create nginx file
Create file /etc/nginx/sites-available/mydomain.com
and add the following contents.
server {
root /var/www/mydomain.com;
index index.html;
listen 80;
listen [::]:80;
server_name mydomain.com www.mydomain.com;
location / {
try_files $uri $uri/ =404;
}
}
Enable the site and test config
If any error comes up, please fix it before proceeding further.
ln -s /etc/nginx/sites-available/mydomain.com /etc/nginx/sites-enabled/mydomain.com
nginx -t
Test the connection
systemctl restart nginx
curl http://mydomain.com
Enable https
If everything is working in the previous steps, enable https.
certbot --nginx -d mydomain.com -d www.mydomain.com
Restart nginx and test
systemctl restart nginx
curl https://mydomain.com