nginx still sends a Server header after server_tokens off
Server: nginxShort answer
server_tokens off stops nginx printing its version number. It does not remove the Server header itself, so you still see Server: nginx. To drop the header entirely, build nginx with the headers-more module and use more_clear_headers. Also check that the directive is loaded where the request is handled.
Fix it fast
1Find out which cause you have
Look at the response headers. If you see Server: nginx without a number, the directive works and only the name is left. If a version is still shown, the setting is not applied to that request.
curl -sI https://example.com | grep -i '^server'2Match what you see, then jump to its fix
- 1
The header reads Server: nginx with no versionserver_tokens only hides the versionFix - 2
A version number is still shown, maybe only on error pages or on one siteThe directive is not set where the request is handledFix - 3
The Server value is your application server's name, not nginxproxy_pass_header Server passes the backend's header throughFix
- 1
What does the error look like?
Server: nginxServer header still present after server_tokens off
Cause 1 of 3
server_tokens only hides the version
1Check
The docs say the directive enables or disables emitting the nginx version on error pages and in the Server header. Only a commercial build can set an empty string to disable the field.
sudo nginx -T 2>/dev/null | grep server_tokens2Fix
With the headers-more module installed and loaded, clear the header. The module can also replace it with more_set_headers.
# in the main context of nginx.conf
load_module /path/to/modules/ngx_http_headers_more_filter_module.so;
# in http, server or location
more_clear_headers Server;3Verify
Test, reload and request again. The Server header is gone.
sudo nginx -t && sudo nginx -s reload
curl -sI https://example.com | grep -i '^server' || echo "no Server header"Confirmed by github.com
Cause 2 of 3
The directive is not set where the request is handled
1Check
server_tokens can be set in http, server and location. A value set in one server block does not cover another.
sudo nginx -T 2>/dev/null | grep -n "server_tokens\|server_name"2Fix
Set it once in the http block so every site inherits it.
http {
server_tokens off;
}3Verify
Request each site and an error page, and check the header.
curl -sI https://example.com/missing-page | grep -i '^server'Confirmed by nginx.org
Cause 3 of 3
proxy_pass_header Server passes the backend's header through
1Check
nginx does not pass Server from a proxied response by default. proxy_pass_header Server turns that off.
sudo nginx -T 2>/dev/null | grep -n "proxy_pass_header"2Fix
Remove proxy_pass_header Server, or hide the header explicitly.
location / {
proxy_pass http://127.0.0.1:3000;
proxy_hide_header Server;
}3Verify
Reload and request the page again.
curl -sI https://example.com | grep -i '^server'Confirmed by nginx.org
How do I stop it coming back?
- Treat hiding the version as hygiene, not as security: keep nginx updated.
- Test response headers in CI with a curl check.
- Check headers on the public URL, since a CDN or load balancer may add its own Server value.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
nginx add_header sets nothing in the response
Header appears on 200 pages but not on 404 or 500 pages
Three things hide add_header.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
Argo CD behind an nginx Ingress loops with too many redirects
307 Temporary Redirect on every request to the Argo CD host
The browser and Argo CD disagree about who handles TLS.
3 causes, each with a fixServers
A Let's Encrypt certificate did not renew with Certbot
Type: connection ... Timeout during connect (likely firewall problem)
Run sudo certbot renew --dry-run and read the Type and Detail lines.
6 causes, each with a fixServers
curl cannot connect to port 80 or 443 on a server running nginx
CURLE_COULDNT_CONNECT (7): Failed to connect() to host or proxy
Exit code 7 means the TCP connection itself failed, before any HTTP happened.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fix