How to add custom HTTP headers

Add custom or security-related HTTP response headers to your application on TurboStack.

Add your own HTTP response headers - most often security headers - with a small piece of custom Nginx configuration.

Before you start

Add security headers

In the server block (or a location), use add_header with the always flag so the header is sent on error responses too:

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

Restrict access to text and log files

A common hardening rule: allow robots.txt, but deny other .txt and .log files.

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
location ~* \.(txt|log)$ {
    deny all;
}

Apply and verify

tscli nginx reload

Check the headers with:

curl -I https://example.com