# Basic Static Website Configuration # Serves HTML, CSS, JS files from /var/www/example.com server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/example.com/html; index index.html index.htm; # Main location - serve files or return 404 location / { try_files $uri $uri/ =404; } # Cache static assets for 1 year location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; # Deny access to hidden files (.git, .htaccess, etc.) location ~ /\. { deny all; access_log off; log_not_found off; } # Custom error pages (optional) error_page 404 /404.html; location = /404.html { internal; } error_page 500 502 503 504 /50x.html; location = /50x.html { internal; } } # Enable with: # sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ # sudo nginx -t && sudo systemctl reload nginx