webzod
account

Serve security.txt over https on nginx

hygiene.security_txt.http_only · effort: minutes

Why it matters

RFC 9116 requires security.txt to be served over https, because a file read over plain http can be altered on the way and send reports to an attacker. Researchers' tools may ignore a file that only exists on http.

The fix

  1. Keep one server block that listens on port 80 only to redirect to https, and serve the file from the https server block.
  2. If the site is behind Cloudflare or another CDN that connects to this server over plain http (Cloudflare Flexible mode), this redirect loops. Switch the CDN to Full (strict) first, or redirect at the CDN instead (Always Use HTTPS).
  3. Run nginx -t, reload nginx and open https://example.com/.well-known/security.txt.
/etc/nginx/conf.d/example.com.conf
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

The examples use example.com. Replace it with your own domain.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.