Generate copy-ready HTTP security header snippets for Nginx or Apache. Choose the protections you need, preview the configuration, and copy it into your server configuration after testing.

HSTS can make a browser refuse HTTP access for the configured period. Do not enable it until HTTPS works reliably, including any subdomains that need HSTS protection.

Choose your options and generate a snippet.

This generator creates a starting configuration only. Review your server version and existing rules, avoid duplicate/conflicting headers, back up configuration, test syntax, and verify headers after deployment. A Content-Security-Policy is intentionally not auto-generated because it must be tailored to each site’s scripts, styles, images and integrations.

Important deployment notes

  • Use only on servers and websites you administer.
  • Test the configuration before reloading or restarting the web server.
  • Check the actual response headers after deployment; a generated snippet does not prove the headers are active.
  • Some applications need framing, camera, microphone or geolocation features. Adjust the selected policies to match your application.

What the main security headers do

  • Strict-Transport-Security (HSTS): tells browsers to use HTTPS only for your site.
  • Content-Security-Policy (CSP): limits where scripts, styles and other content may load from, reducing the impact of cross-site scripting.
  • X-Content-Type-Options: stops browsers from guessing file types.
  • Referrer-Policy: controls how much page address information is shared with other sites.
  • Permissions-Policy: restricts browser features such as the camera or microphone.
  • Clickjacking protection: X-Frame-Options or the CSP frame-ancestors directive prevents your pages being embedded in a malicious frame.

How to use the generated snippets

  1. Select the headers you want and review the preview.
  2. Copy the Nginx or Apache snippet into your configuration.
  3. Test the configuration, reload the server and check the real response headers.

Test before you enforce

A strict CSP or HSTS setting can break scripts, embeds or subdomains if applied carelessly. Start with conservative values, keep a backup of your configuration, and verify results with our Security Headers Analyzer. Our guide to checking website security headers explains each setting in more detail.

Frequently asked questions

Which header matters most?

HSTS and a well-tested CSP give the biggest benefit, but all of them work best together with HTTPS and regular updates.

Can headers make my site fully secure?

No. They add protection layers but do not replace updates, strong access control or backups.

Does this work on managed hosting?

Many managed hosts and WordPress.com plans limit server settings, so check what your provider allows.

This tool is for education and general use.