Security Headers Generator

Generate the HTTP security headers a site should send.

Security Headers Generator tool

Headers to include

What each header does

About the Security Headers Generator

Security headers tell browsers to enforce protections that a page cannot enforce on its own, such as always using HTTPS, refusing to sniff file types and limiting what information leaks to other sites. This security headers generator assembles the headers you choose into configuration for Apache, nginx, Netlify or Vercel, and explains what each one does and the risks of setting it too strictly, so you understand what you are deploying rather than copying lines blindly. Test changes on a staging site first, since an overly strict policy can break embedded content. For a script and resource whitelist, build a policy with the CSP Generator, and for checking content types, the MIME Type Lookup.

The set covers the headers that are genuinely worth sending today. Strict-Transport-Security makes browsers use https every time, X-Content-Type-Options stops them guessing file types, and X-Frame-Options keeps other sites from framing your pages for clickjacking. Referrer-Policy limits how much of your address leaks to sites you link to, Permissions-Policy switches off browser features you never use, and Cross-Origin-Opener-Policy keeps your pages in their own process.

Two warnings are built in because they matter. Once browsers have cached a long HSTS lifetime, especially with preload added, there is no quick way back, so any site still sorting out its certificates should begin with a lifetime of minutes or days. And headers that used to be recommended but now cause harm, X-XSS-Protection in particular, are explained instead of being offered as options.

How to use the Security Headers Generator

  1. Pick your platformChoose the web server or hosting service you deploy to, or a neutral list of headers.
  2. Choose the headersEach one comes with an explanation of what it does and its settings.
  3. Read the warningsPay particular attention to HSTS, which is difficult to reverse.
  4. Copy the configurationAdd it to your server settings, then check the headers your site actually returns.

Security Headers Generator features

  • HSTS with max-age, includeSubDomains and preload settings
  • MIME sniffing, framing and referrer controls
  • Permissions-Policy covering the common browser features
  • Cross-Origin-Opener-Policy and Cross-Origin-Resource-Policy
  • Output for Apache, nginx, Netlify, Vercel or as a plain list
  • Plain explanations of each header and its trade-offs
  • Warnings about HSTS settings that are hard to undo
  • Notes on obsolete headers and why to avoid them

Common uses

  • Tightening a site before a security audit
  • Adding the headers a scanner reported as missing
  • Stopping full addresses from leaking through the Referer header
  • Disabling camera, microphone or location access a site never needs
  • Translating a set of headers from one server platform to another

Security headers in practice: adding them on nginx, the inheritance trap, referrer and permissions policies, and checking the result

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Security headers cost nothing to send and protect every visitor, yet they are missing from a large share of websites because adding them correctly involves a few traps. This guide works through adding headers to an nginx server, such as one managed through CloudPanel, explains the two configuration mistakes that silently remove headers, covers the referrer and permissions policies in practical terms and shows how to confirm what browsers actually receive.

A worked example: rolling out headers on nginx

A site owner adds these lines to the server block of the site's nginx configuration:

  • add_header X-Content-Type-Options "nosniff" always;
  • add_header Referrer-Policy "strict-origin-when-cross-origin" always;
  • add_header Strict-Transport-Security "max-age=300" always;

The HSTS header starts with a five-minute lifetime. After a week without problems on any page or subdomain, the value is raised to one day and then to 31536000 seconds, one year. Starting small means a mistake can be undone within minutes rather than being remembered by visitors' browsers for a year.

The inheritance trap

In nginx, add_header lines in a location block replace all the headers defined in the surrounding server block rather than adding to them. A site that sets security headers at server level and then adds a caching header inside a location block for images will find that images are served without any security headers at all. The fix is to repeat the security headers in each location block that has its own add_header lines, or to keep them in a shared include file.

The always parameter

Without the word always, nginx adds headers only to successful and redirect responses. Error pages such as 404 and 500 are then sent without protection, and those pages can still be framed or sniffed. Adding always to each security header applies it to every response, which is what you almost always want.

Referrer policy in practice

When a visitor clicks a link to another site, the browser may tell that site which page they came from. The value strict-origin-when-cross-origin sends the full address only within your own site and just the domain to other sites, which keeps analytics working while hiding paths. Pages whose URLs contain secrets, such as password reset links with tokens, are safer with no-referrer, so the token never reaches a third party through an embedded image or link.

Permissions policy without breaking features

A permissions policy switches off browser features your pages do not use, such as camera=(), geolocation=(). Care is needed on sites with tools that do use them. A page offering speech-to-text needs the microphone, so its policy must allow it for the site itself with microphone=(self) rather than disabling it. Setting the policy per page, or allowing features only where they are needed, keeps protection without breaking tools.

Cross-origin opener policy and popups

The Cross-Origin-Opener-Policy: same-origin header isolates your pages from windows opened by other sites, which protects against some cross-window attacks. It can, however, break sign-in and payment flows that open a popup and wait for it to report back. The value same-origin-allow-popups keeps that working, so test login with external providers and checkout before tightening this header.

Caches and CDNs

When a site sits behind Varnish or a CDN, headers set on the web server usually pass through, but some services add, remove or override headers of their own. Always check the final response that visitors receive, not just the server configuration. After changing headers, purge the cache, because cached pages keep their old headers until they expire.

Checking the result

Run curl -I against a normal page, an image, a PDF and a missing page to see the headers each returns. In the browser, the Network panel shows response headers for every request. Online header scanners give a quick overall grade, but checking several kinds of response yourself is what catches the inheritance and error-page problems described above.

Common mistakes

  • Defining headers at server level and losing them inside location blocks.
  • Omitting the always parameter, leaving error pages unprotected.
  • Starting HSTS with a one-year lifetime before testing every subdomain.
  • Disabling the microphone or camera on pages whose tools need them.

Related tools

To build a content security policy, use CSP Generator. For Apache servers, try .htaccess Generator, and to check the content types your files are served with, MIME Type Lookup.

Uploaded files

Files that users upload and that your site later serves, such as profile photos or PDF documents, deserve extra care. Serving them from a separate subdomain, with nosniff and a header forcing download for risky types, limits the damage if a harmful file slips past checks. The main site's cookies and pages then stay out of reach of anything uploaded.

Keeping a record

Headers set by hand on one server are easily lost when a site moves to new hosting or a server is rebuilt. Keeping the configuration in version control, or in a documented include file, means the headers move with the site. After any migration, repeat the checks above on the new server before switching traffic to it.

Privacy

The configuration is generated in your browser. Your domain and settings are not sent anywhere or stored.

Frequently asked questions

Which header is the best one to add first?

X-Content-Type-Options set to nosniff. It takes one fixed value, has no side effects on a normal site and prevents a genuine category of exploit. Referrer-Policy comes a close second and is just as safe to switch on.

Why is a mistake with HSTS so serious?

For as long as the lifetime you chose, every browser that has seen the header will insist on https for your domain. If https later fails, visitors cannot reach you, and changing the header will not help them, so start short and increase it gradually.

Should I use the preload option?

Only when you are completely sure. Preloading adds your domain, including every subdomain, to a list built into browsers, and getting it removed takes months. Treat it as the final step, taken only after months of trouble-free https.

Do I still need X-Frame-Options?

Its job has been taken over by the frame-ancestors directive of a Content Security Policy, which is more flexible. Sending both remains the practical choice while some older browsers are still in use.

Should I send X-XSS-Protection?

No. Modern browsers dropped the filter it switched on, and before they did, researchers showed the filter could itself be abused. A well-written Content Security Policy is the modern protection against cross-site scripting.

Can security headers replace fixing vulnerabilities?

No. They are an extra layer of defence. If your code lets attackers inject content, a header may stop some of the damage, but the hole is still there until a developer closes it.