Server configuration
Each example below sends the header and serves check files as
text/plain with no-store. For the check directory
and anything unpublished under it, each returns a 404, not a redirect.
nginx
add_header Security-Testing 'not-authorized; check="/.well-known/security-testing/"' always;
location = /.well-known/security-testing { return 404; }
location /.well-known/security-testing/ {
types { }
default_type "text/plain; charset=utf-8";
try_files $uri =404;
# add_header here replaces the server's, so repeat it
add_header Security-Testing 'not-authorized; check="/.well-known/security-testing/"' always;
add_header Cache-Control no-store always;
}Apache
Header always set Security-Testing "not-authorized; check=\"/.well-known/security-testing/\""
RedirectMatch 404 ^/\.well-known/security-testing/?$
<LocationMatch "^/\.well-known/security-testing/.">
ForceType "text/plain; charset=utf-8"
Header always set Cache-Control no-store
</LocationMatch>
Apache needs mod_headers. Without it, these lines stop the server from starting. Keep only proof files in the check directory: Apache lists a folder inside it by default.
Cloudflare Pages (_headers)
- Put the site in one folder, with a top-level
404.html. Without it, Pages answers every unknown path with index.html and a 200, and the check can't work. - Add a file named
_headersto the root of that folder:/* Security-Testing: not-authorized; check="/.well-known/security-testing/" /.well-known/security-testing/* Content-Type: text/plain; charset=utf-8 Cache-Control: no-store - Create a Pages project from the Git repository. Set the framework preset to None, leave the build command empty, and set the build output directory to the folder from the first step.
- Add your domain to the project. If the site answers on more than one name, redirect the others to the main one with a 301 (in Cloudflare, a Redirect Rule), so one host serves security.txt and the check.
- Check it: an unknown path and
/.well-known/security-testing/both return 404 with no redirect, and every response from the site carries the Security-Testing header.