Headers & CORS in Apache

From the Apache cheat sheet ยท Security & Access Control ยท verified Jul 2026

Headers & CORS

Set security headers and configure CORS with mod_headers

apacheconf
# Enable mod_headers
# sudo a2enmod headers

# Security headers
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set Strict-Transport-Security "max-age=31536000"
๐Ÿ’ก ServerTokens Prod hides your Apache version from response headers โ€” basic security hygiene
โšก HSTS with preload tells browsers to ALWAYS use HTTPS โ€” submit to hstspreload.org
๐Ÿ“Œ Never use Access-Control-Allow-Origin "*" with credentials โ€” use specific origins instead
๐ŸŸข Use SetEnvIf to dynamically set CORS origin from a whitelist of allowed domains
headerscorssecurity

More Apache tasks

Back to the full Apache cheat sheet