# Nginx SPA fallback for www.baskbuddy.com # Drop this snippet into your server {} block and set root to the dist/ folder. # Canonical host is www.baskbuddy.com — it is the only name with a DNS A record, # and it is what canonical / og:url / hreflang / sitemap all advertise. # The apex is redirected to www so the two never compete in search results. server { listen 80; server_name baskbuddy.com; return 301 http://www.baskbuddy.com$request_uri; } server { listen 80; server_name www.baskbuddy.com; root /var/www/baskbuddy/dist; index index.html; # gzip for SPA assets gzip on; gzip_types text/plain text/css application/javascript application/json image/svg+xml; # SEO files — must be revalidated often. Keep this block ABOVE the generic # static-asset block below: nginx picks the first matching regex, and caching # robots.txt / sitemap.xml as "immutable" for 6 months would hide any update # from crawlers long after a deploy. location ~ ^/(robots\.txt|sitemap\.xml)$ { expires 1h; access_log off; add_header Cache-Control "public, max-age=3600"; } # content-hashed or effectively immutable static assets location ~* \.(?:webp|png|jpg|jpeg|mp4|webm|svg|ico|woff2?|css|js)$ { expires 6M; access_log off; add_header Cache-Control "public, immutable"; } # hashed Vite assets live under /assets/ with content-hash filenames location /assets/ { expires 1y; access_log off; add_header Cache-Control "public, immutable"; } # all other routes fall back to index.html for React Router location / { try_files $uri $uri/ /index.html; } } # HTTPS (recommended) — after obtaining a certificate, redirect 80 -> 443 and # serve both names from 443, keeping the apex -> www redirect there as well: # server { # listen 443 ssl http2; # server_name baskbuddy.com; # include /path/to/ssl.conf; # return 301 https://www.baskbuddy.com$request_uri; # } # server { # listen 443 ssl http2; # server_name www.baskbuddy.com; # root /var/www/baskbuddy/dist; # include /path/to/ssl.conf; # location / { try_files $uri $uri/ /index.html; } # }