Project: Static Site with HTTPS
Introduction
This project deploys a static website to /var/www/, serves it with Nginx, enables gzip and cache headers, and obtains HTTPS with Certbot. You combine chapters on static files, performance, and TLS into one checklist you can repeat for portfolio or marketing pages.
Prerequisites
- Serving Static Files
- HTTPS and Let's Encrypt
- gzip and Static Performance
- Domain name pointing to your VPS (for real TLS)
Project Goals
- Static files under
/var/www/portfolio/ - HTTP redirects to HTTPS
- Long cache for assets, short cache for
index.html - gzip for text types
Step 1: Prepare Site Files
Local build or sample:
portfolio/
├── index.html
├── css/
│ └── styles.css
└── assets/
└── logo.svgDeploy:
sudo mkdir -p /var/www/portfolio
sudo rsync -av ./portfolio/ /var/www/portfolio/
sudo chown -R www-data:www-data /var/www/portfolio
sudo find /var/www/portfolio -type d -exec chmod 755 {} \;
sudo find /var/www/portfolio -type f -exec chmod 644 {} \;Step 2: HTTP server Block (Before TLS)
/etc/nginx/sites-available/portfolio:
Enable:
sudo ln -sf /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
curl -I http://example.com/Step 3: Certbot HTTPS
sudo certbot --nginx -d example.com -d www.example.comChoose redirect HTTP to HTTPS. Certbot updates config with listen 443 ssl and certificates.
Verify:
curl -I https://example.com/
sudo certbot renew --dry-runStep 4: Post-Certbot Tweaks
Re-apply gzip and cache inside the 443 server block if Certbot created a new block—merge your location rules into the SSL server.
Optional security headers:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;Acceptance Checklist
-
https://example.com/shows your page with padlock -
http://example.com/redirects to HTTPS -
curl -I https://example.com/assets/logo.svgshows longCache-Control -
curl -I -H "Accept-Encoding: gzip" https://example.com/css/styles.cssshowsContent-Encoding: gzip -
sudo nginx -tpasses after all edits
Extensions
- Add custom
404.html - Add
www→ apex redirect in dedicatedserverblock - Link from HTML static deployment
FAQ
No domain yet?
Practice HTTP on demo.local with /etc/hosts; skip Certbot until DNS exists.
Certbot overwrote my locations?
Merge manually; keep one SSL server with all location blocks.
Deploy updates?
rsync new files; browsers pick up new index.html due to no-cache.