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

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:

text
portfolio/
├── index.html
├── css/
│   └── styles.css
└── assets/
    └── logo.svg

Deploy:

bash
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:

bash
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

bash
sudo certbot --nginx -d example.com -d www.example.com

Choose redirect HTTP to HTTPS. Certbot updates config with listen 443 ssl and certificates.

Verify:

bash
curl -I https://example.com/
sudo certbot renew --dry-run

Step 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:

nginx
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.svg shows long Cache-Control
  • curl -I -H "Accept-Encoding: gzip" https://example.com/css/styles.css shows Content-Encoding: gzip
  • sudo nginx -t passes after all edits

Extensions

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.