ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Web Security

Security Headers Configuration

Essential HTTP security headers with copy-paste Nginx and Apache configs for CSP, HSTS, and more.

3 snippets Beginner security-headers-scanner
CSPHSTSX-Frame-OptionsNginxApache

What you'll learn

  • Nginx config
  • Apache .htaccess
  • Express.js middleware

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

3 ready-to-use snippets for security headers configuration. Click copy and paste into your project.

Nginx config
                add_header Content-Security-Policy
  "default-src 'self'; script-src 'self'";
add_header Strict-Transport-Security
  "max-age=63072000; includeSubDomains; preload";
add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "DENY";
add_header Referrer-Policy
  "strict-origin-when-cross-origin";
add_header Permissions-Policy
  "camera=(), microphone=(), geolocation=()";
              
Apache .htaccess
                <IfModule mod_headers.c>
  Header set Content-Security-Policy
    "default-src 'self'"
  Header set Strict-Transport-Security
    "max-age=63072000; includeSubDomains; preload"
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "DENY"
  Header set Referrer-Policy
    "strict-origin-when-cross-origin"
  Header set Permissions-Policy
    "camera=(), microphone=(), geolocation=()"
</IfModule>
              
Express.js middleware
                const helmet = require('helmet');
app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      scriptSrc: ["'self'"],
      styleSrc: ["'self'", "'unsafe-inline'"],
      imgSrc: ["'self'", 'data:', 'https:'],
    }
  },
  hsts: { maxAge: 63072000, includeSubDomains: true, preload: true }
}));
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site