Skip to content
How to Hide Nginx Version and Set a Custom Server Header

How to Hide Nginx Version and Set a Custom Server Header

This guide walks you through downloading, compiling, and configuring Nginx so that the server version is hidden and a custom Server header is displayed, including step‑by‑step commands, source code edits, and verification methods.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations

nginx not only can hide version information, it also supports custom web server information.

First, see the final hidden result.

The implementation is straightforward:

1. Download the latest stable version from the official site.

wget http://nginx.org/download/nginx-1.14.1.tar.gz

2. Extract the archive.

tar -xf nginx-1.14.1.tar.gz</code>
<code>cd nginx-1.14.1

3. Modify the C source files:

(1) Edit src/http/ngx_http_header_filter_module.c (line 49) to replace the default Server string:

static u_char ngx_http_server_string[] = "Server: Please guess it!" CRLF;

(2) Edit src/http/ngx_http_special_response.c (line 36) to add the same string:

<hr><center><strong>Please guess it!</strong></center>" CRLF

4. Configure the build: ./configure --prefix=/usr/local/nginx 5. Compile and install: make && make install 6. Edit the Nginx configuration file to turn off version tokens:

vim /usr/local/nginx/conf/nginx.conf</code>
<code>... </code>
<code>http {</code>
<code>    server_tokens off;</code>
<code>    ...</code>
<code>}

7. Start Nginx: /usr/local/nginx/sbin/nginx 8. Test the result:

[root@node1 nginx-1.14.1]# curl -I http://127.0.0.1</code>
<code>HTTP/1.1 200 OK</code>
<code>Server: Please guess it!</code>
<code>Date: Wed, 07 Nov 2018 19:15:43 GMT</code>
<code>...

Visit the server with a browser to confirm the custom header appears.

Notes:

If you only want to hide the version number without customizing the server string, skip step 3.

You can also customize the string while upgrading Nginx by modifying the C files before running ./configure and make.

For detailed Nginx upgrade instructions, see https://www.cnblogs.com/Sunzz/p/9953443.html.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendsecurityversion hidingcustom server header
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.