VisualNest Get your plan

Blog / Security

HTTP security headers: a practical guide for website owners

The six HTTP security headers every website should send, what each protects against, and copy-paste settings for Apache and Nginx.

Security headers are short instructions your web server sends with every page. They cost nothing, take minutes to add, and block entire classes of attacks such as cross-site scripting, clickjacking and protocol downgrades. Yet most small business websites send none of them.

This guide covers the six headers that matter most, in order of impact, with settings you can copy.

1. Strict-Transport-Security (HSTS)

HSTS tells browsers to only ever connect to your site over HTTPS. Without it, the first request a visitor makes can be quietly downgraded to plain HTTP by anyone on the same network, such as a fake café Wi-Fi hotspot.

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

Use a max-age of at least one year. Only add includeSubDomains once every subdomain works over HTTPS.

2. Content-Security-Policy (CSP)

CSP lists where scripts, styles, images and other resources may load from. If an attacker manages to inject a script into your page, a good policy stops the browser from running it. It is the strongest defence against cross-site scripting (XSS).

A safe starting point:

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'

CSP is the one header that can break things, because it blocks any script your site loads from somewhere you have not listed. Add it as Content-Security-Policy-Report-Only first, open your site with the browser console visible, and add the sources you really use before switching to the enforcing header. Avoid 'unsafe-inline' for scripts where you can: it allows exactly the kind of injected code CSP is meant to stop.

3. Clickjacking protection

Clickjacking loads your site inside an invisible frame on another page and tricks visitors into clicking buttons they cannot see. Stop it with either header:

Header always set X-Frame-Options "SAMEORIGIN"

If you use CSP, the frame-ancestors 'self' directive does the same job.

4. X-Content-Type-Options

This stops browsers from guessing a file's type. Without it, a text file or image upload could be treated as a script.

Header always set X-Content-Type-Options "nosniff"

5. Referrer-Policy

When a visitor clicks a link to another site, the browser can send the full address of the page they came from. That address may include search terms, order numbers or tokens. This setting sends only your domain to other sites:

Header always set Referrer-Policy "strict-origin-when-cross-origin"

6. Permissions-Policy

Switch off browser features your site does not use, so no script on your pages can ask for them:

Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()"

Remove headers that give information away

Headers like Server: Apache/2.4.41 or X-Powered-By: PHP/7.4 tell attackers exactly which software versions to look up. Hide them:

ServerTokens Prod
Header always unset X-Powered-By

On shared hosting you usually cannot change ServerTokens, but you can still remove X-Powered-By in .htaccess.

Where to add these settings

  • Apache or LiteSpeed hosting (most shared hosts, including Hostinger and cPanel hosts): add the lines to the .htaccess file in your website's main folder, inside an <IfModule mod_headers.c> block.
  • Nginx: use add_header ... always; in your server block.
  • WordPress: add them to .htaccess, or use a security headers plugin if you cannot edit files.

Test your site

Run our free security headers check to see which headers your site sends today. It grades the result and gives you the exact lines to add for Apache and Nginx.

Chat on WhatsApp