HTTP security headers are a few lines your web server adds to every response. They tell the browser to refuse the things attackers rely on: loading the site over plain HTTP, showing it inside someone else’s page, guessing file types, running scripts from anywhere. They cost nothing and take minutes to add, and most sites still do not send them. This guide shows how to check your own site with one command and how to add what is missing.

We tested the Nginx steps in our lab on Ubuntu 24.04 with Nginx 1.24 in November 2026, and the outputs are real. The Apache lines are from the Apache documentation and we did not run them in our lab.

The short answer

curl -sI https://yourcompany.com | grep -iE '^(strict-transport-security|content-security-policy|x-content-type-options|x-frame-options|referrer-policy|permissions-policy)'

Each line that comes back is a header your site sends. Six lines is a full set. Nothing back means none.

What we see on real sites

Our free website safety check tests these headers. Between 25 October and 13 November 2026 people ran it on 10 different sites. The sample is small, and the pattern is still clear:

HeaderSites that did not pass
Content-Security-Policy9 of 10
Permissions-Policy8 of 10
Referrer-Policy8 of 10
X-Content-Type-Options7 of 10
Strict-Transport-Security5 of 10
X-Frame-Options or frame-ancestors5 of 10

Free tool: run the website safety check on your own domain. It tests these headers along with HTTPS and the certificate and gives a grade from A+ to F in about 30 seconds.

What each header does

HeaderWhat it stopsA safe starting value
Strict-Transport-SecurityVisits over plain HTTP after the first secure onemax-age=31536000
X-Content-Type-OptionsThe browser guessing a file’s type and running it as scriptnosniff
X-Frame-OptionsYour pages shown inside a frame on another site (clickjacking)SAMEORIGIN
Referrer-PolicyFull page addresses leaking to other sites when users click a linkstrict-origin-when-cross-origin
Permissions-PolicyPages or embedded content using the camera, microphone or locationcamera=(), microphone=(), geolocation=()
Content-Security-PolicyScripts and other content loading from sources you did not approveStart in report-only mode, see below

Before: a default Nginx site

curl -skI https://127.0.0.1/
HTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html

No security headers, and the Server line tells every visitor the exact version and operating system.

Add the headers in Nginx

Put the headers in one file so every site on the server can include it. Create /etc/nginx/snippets/security-headers.conf:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy-Report-Only "default-src 'self'" always;

Then, inside the server block of the site:

server_tokens off;
include snippets/security-headers.conf;

Test the configuration and reload:

sudo nginx -t
sudo systemctl reload nginx

After

HTTP/1.1 200 OK
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Content-Security-Policy-Report-Only: default-src 'self'

The version is gone from the Server line and the headers are there. The word always at the end of each line matters. Without it Nginx adds the headers only to successful responses. With it, our lab server also sent them on a 404 page, which is what you want.

Three things that go wrong

Headers vanish in one location. In Nginx, a location block that has its own add_header line stops inheriting the ones from the server block. If a location adds a cache header, include the snippet there again.

HSTS locks out a subdomain. includeSubDomains applies to every subdomain, including an old intranet page or a device panel that only works over HTTP. If you are not sure all of them have HTTPS, start with max-age=86400 and no includeSubDomains, then raise it. Leave preload out until you have read what it commits you to, because removal takes months.

CSP breaks the site. A strict Content-Security-Policy blocks every inline script, analytics tag and payment widget you did not tell it about. Start with the Content-Security-Policy-Report-Only header, as in the snippet above. Browsers then report what the policy would block and block nothing. Collect reports for a few weeks, add the sources you really use, and only then switch the header name to Content-Security-Policy. Our own site runs its policy in report-only mode for that reason.

The same in Apache

Enable the headers module with sudo a2enmod headers, then add to the virtual host or .htaccess:

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"

On shared hosting where you cannot edit the server config, the same lines usually work in .htaccess. On WordPress, a security plugin or a short code snippet can send them from PHP.

Headers you can stop adding

  • X-XSS-Protection belongs to a filter that current browsers have removed. Leave it out or set it to 0.
  • Expect-CT and Public-Key-Pins no longer work in current browsers.
  • X-Frame-Options is being replaced by the frame-ancestors directive of CSP. Send both for now.

What headers do not fix

Headers are instructions to the browser. They do not patch a vulnerable plugin, stop a weak admin password or protect an API that other programs call. Treat them as one layer. The server behind them still needs the basics in our secure Nginx configuration guide.

Related guides

Sources

Want the application behind the headers tested? Our VAPT services test your website and servers the way an attacker would and give you a prioritised fix list. Contact us for a quote.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply