Nginx / Security / Server Setup

How to remove the Server header in nginx

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install nginx, Varnish and lots of useful modules for them, this is your one stop repository to get all performance related software.
You have to maintain an active subscription in order to be able to use the repository!

Security through obscurity isn’t the holy grail that will make your website secure completely. But it doesn’t mean you shouldn’t use it. As a complementary security measure, it must be used.

nginx, by default, sends information about its use in the Server HTTP header as well as error pages, e.g.: nginx/1.14.0.

Hide version information

The standard security solution you might be already using in these regards is hiding nginx version information. In your nginx.conf:

http {
   ...
   server_tokens off;
   ...
}

This only hides the specific version of nginx from the Server header and error pages.

However, it’s much better to remove the Server header completely.

Hide the Server header

You can easily achieve this by using a third party modules

Using ngx_security_headers

If you’re using our RPM repository in nginx, it’s easy to install with yum install nginx-module-security-headers.

Now you can adjust your nginx.conf like this:

load_module modules/ngx_http_security_headers_module.so;

http {
    ...
    security_headers on;
    ...
}

Using Headers More.

If you’re using our RPM repository in nginx, it’s easy to install with yum install nginx-module-headers-more.

Now you can adjust your nginx.conf like this:

load_module modules/ngx_http_headers_more_filter_module.so;

http {
    ...
    more_clear_headers Server;
    ...
}

While this a great solution, you might notice that the default error pages by nginx still output the “nginx” word in them.

Hide use of nginx altogether

So you may want to adjust nginx sources to prevent output of information disclosure for your use of nginx software. You’ll have to recompile nginx to achieve this.

sed -i 's@"nginx/"@"-/"@g' src/core/nginx.h
sed -i 's@r->headers_out.server == NULL@0@g' src/http/ngx_http_header_filter_module.c
sed -i 's@r->headers_out.server == NULL@0@g' src/http/v2/ngx_http_v2_filter_module.c
sed -i 's@<hr><center>nginx</center>@@g' src/http/ngx_http_special_response.c

Citrus Stack server users already have secure nginx version, which doesn’t need this.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.