Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

nginx still sends a Server header after server_tokens off

ErrorServer: nginx

Short 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.

  • Applies to nginx 1.26, headers-more module
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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'
  2. 2Match what you see, then jump to its fix

    1. 1The header reads Server: nginx with no versionserver_tokens only hides the versionFix
    2. 2A version number is still shown, maybe only on error pages or on one siteThe directive is not set where the request is handledFix
    3. 3The Server value is your application server's name, not nginxproxy_pass_header Server passes the backend's header throughFix

What does the error look like?

  • Server: nginx
  • Server 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_tokens

2Fix

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

Did this fix it?

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

Did this fix it?

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

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.