conf.d/ and sites-enabled/ are equivalent: pick one and stick with it.
Personally I prefer the sites-available/ + sites-enabled/ pair (the Debian default): one file per domain in sites-available/, and a symlink in sites-enabled/ to “turn it on”.
This way certbot --nginx discovers your vhosts automatically, and you can disable a domain with a single rm of the symlink, without losing the file.
Anatomy of a vhost
A server block (vhost) tells Nginx how to handle requests for a given domain.
server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/example; # filesystem root for static files index index.html; location / { try_files $uri $uri.html $uri/ =404; }}
This is a vhost basic starting configuration. Why?
Because for 443, Certbot automatically sets everything up when you do this:
This wiki is a static site (Quartz output), then served by Nginx with HTTPS issued by Certbot.
The vhost lives in /etc/nginx/sites-available/wiki.farnetiandrea.it, enabled via a symlink in /etc/nginx/sites-enabled/.
The other domain farnetiandrea.it (a small landing page + a reverse-proxied Node app called OfficeGamble) has its own file /etc/nginx/sites-available/farnetiandrea.it, one file per domain:
Nginx does not expand ~ to the user’s home directory, that’s a shell convention, not an Nginx one!
In a real config, use the absolute path (e.g. /var/www/wiki or the full home path): ~/wiki/public is shown here only to keep the example free of personal account details.
reload is a graceful restart: no dropped connections.
Use restart only when you change nginx.conf itself.
Run HTTPS
Nginx doesn’t issue certificates on its own.
Pair it with Certbot: a single sudo certbot --nginx -d your-domain.comautomatically adds listen 443 ssl, the cert paths, and an HTTP→HTTPS redirect to the existing vhost, plus auto-renewal via certbot.timer… and the day you’ll want to look inside them (check expiration, inspect SAN, verify chain, convert format) check out the TLS certificates reference for the openssl one-liners you’ll need.
Useful commands
Command
What it does
sudo nginx -t
Validate the entire config
sudo nginx -T
Validate and dump the merged config (great for debugging)