How to Hide Nginx Server Version in Linux

In this short article, we will show you how hide Nginx server version on error pages and in the “Server HTTP” response header field in Linux. This is one of the key recommended practices in securing your Nginx HTTP and proxy server.

Read Also: How to Hide Apache Version Number and Other Sensitive Info

This guide assumes that you already have Nginx installed on your system or setup the full LEMP stack by following any of these tutorials below based on your Linux distribution:

  1. How to Install LEMP (Linux, Nginx, MariaDB, PHP-FPM) on Debian 9 Stretch
  2. How to Install Nginx, MariaDB and PHP (FEMP) Stack on FreeBSD
  3. How To Install Nginx, MariaDB 10, PHP 7 (LEMP Stack) in 16.10/16.04
  4. Install Latest Nginx 1.10.1, MariaDB 10 and PHP 5.5/5.6 on RHEL/CentOS 7/6 & Fedora 20-26

The “server_tokens” directive is responsible for displaying the Nginx version number and Operating system on error pages and in the “Server” HTTP response header field as shown in the following screenshot.

Nginx Version Number
Nginx Version Number

To disable this, you need to turn off the server_tokens directive in /etc/nginx/nginx.conf configuration file.

# vi /etc/nginx/nginx.conf
$ sudo nano /etc/nginx/nginx.conf

Add the following line to http context as shwon in the screen shot below.

server_tokens off;
Turn Off Server Tokens in Nginx
Turn Off Server Tokens in Nginx

After adding above line, save the file and restart Nginx server to take new changes into effect.

# systemctl restart nginx
$ sudo systemctl restart nginx

Now verify if its working.

Hide Nginx Version
Hide Nginx Version

Note: This will only hide the server version number, but not the server signature (name). If you want to hide the server name, compile Nginx from sources and include the --build=name option to set a nginx build name.

If you are running PHP in your Nginx web server, I suggest you to Hide PHP Version Number.

To further secure and harden Nginx web server, check out our comprehensive guide to securing Nginx in Linux, which you will find useful:

  1. The Ultimate Guide to Secure, Harden and Improve Performance of Nginx Web Server

In this article, we explained you how to hide Nginx server version in error pages and “Server” HTTP response header field, in Linux. If you have any queries, use the comment form below to reach us.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

2 thoughts on “How to Hide Nginx Server Version in Linux”

  1. You can edit /usr/sbin/nginx with an editor and change where it says nginx/x.x.x.x to 00000/x.x.x.x.

    Except where nginx call its files folder, where usually it is associated to …/nginx/somefile or /usr/share/nginx/somefile.

    nginx have 5 letters, replace its name for other 5 characters, not 4 not 6, 5 as it is.

    This is to change nginx name without having to compile it manually.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.