Add a new website to a server running nginx, LetsEncrypt HTTPS and Certbot
Last updated on June 2026.
This is follow up note from https://yctct.com/setup-webserver to add a second website on the same web server.
Update DNS
In the DNS, point the domain name example.com or a subdomain www.example.com or both to the IP address of VPS.
A @ IP_address_of_server # for the domain name
A www IP_address_of_server # for the www subdomain
Configure web server
Read:
- https://fedfree.org/docs/http/debian-nginx.html#introduction-3
- https://fedfree.org/docs/http/debian-nginx.html#do-not-configure-the-hostname-first
Follow FedFree’s instructions:
TL;DR from fedfree:
Make website directory:
# mkdir -p /var/www/example.com
Create nginx host file, for the site — create the file:
# touch /etc/nginx/sites-available/example.com
Enable the website:
# cd /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-available/example.com example.com
configure the site, populate /etc/nginx/sites-available/example.com with:
# HTTP (plain, unencrypted)
# Automatically redirects to HTTPS,
# except for LetsEncrypt ACME challenges
server {
server_name
www.example.com example.com;
# you could add subdomains to server_name aswell
# for example: server_name git.example.com www.example.com example.com;
# you would then add an entry, similar to the `server_name example.com`
# server below
listen 80;
listen [::]:80;
location / {
return 301 https://$host$request_uri;
}
location ^~ /.well-known/acme-challenge {
# override the above rule, only for LetsEncrypt challenges.
# this will enable certbot renew to work, without stopping
# or otherwise reconfiguring nginx in any way
default_type text/plain;
root /var/www/letsencrypt;
# in this case, the 301 redirect rule does not apply, because
# this location block shall override that rule
}
}
# HTTPS: redirect www.example.com to example.com
server {
server_name www.example.com;
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/www.example.com/chain.pem;
disable_symlinks on;
return 301 https://example.com$request_uri;
}
# HTTPS: this is your actual website configuration
server {
server_name example.com;
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
root /var/www/example.com;
index index.html;
disable_symlinks on;
# uncomment this to enable autoindexing, otherwise directories
# without html index files will return HTTP 403
# DO NOT turn on autoindex unless you're sure you need it, because
# it's a potential security threat under some circumstances
# autoindex on;
}
Generate a LetsEncrypt certificate
Read:
Generate a LetsEncrypt certificate for the new website, for the domain name:
# certbot certonly --webroot -w /var/www/example.com --rsa-key-size 4096 --agree-tos -w /var/www/letsencrypt -d example.com --register-unsafely-without-email
for the subdomain www, for example:
# certbot certonly --webroot -w /var/www/example.com --rsa-key-size 4096 --agree-tos -w /var/www/letsencrypt -d www.example.com --register-unsafely-without-email
Then you can check that example.com and www.example directories are created:
# ls /etc/letsencrypt/live/
About --webroot: https://eff-certbot.readthedocs.io/en/stable/using.html#webroot.
Place index.html in root
# touch /var/www/example.com/index.html
or the folder of your site.
Add CAA to DNS
example.com. CAA 128 issue "letsencrypt.org"
CAA creates a DNS mechanism that enables domain name owners to whitelist CAs that are allowed to issue certificates for their hostnames.
Long story: https://blog.qualys.com/product-tech/2017/03/13/caa-mandated-by-cabrowser-forum
more informaorgtion on CAA: https://letsencrypt.org/docs/caa/
Tests
Run curl tests and the SSL test (you should get A+), see: https://fedfree.org/docs/http/debian-nginx.html#tests
Then:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
And reload nginx:
# systemctl reload nginx
Back up the LetsEncrypt certificate
Back up the LetsEncrypt directory: https://yctct.com/backup-letsencrypt-folder-from-remote-to-local
Renew LetsEncrypt certificate automatically
See: https://yctct.com/renew-certificates
personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki nginx hosting letsencrypt certbot