Operations 4 min read

How to Hide Nginx Version and Set a Custom Server Header

This step‑by‑step guide shows how to download, compile, and configure Nginx so that the version information is hidden and a custom Server header (e.g., "Please guess it!") is displayed, including code modifications, build commands, and verification.

Raymond Ops
Raymond Ops
Raymond Ops
How to Hide Nginx Version and Set a Custom Server Header

nginx can not only hide its version information but also display a custom Server header.

First, download the latest stable source package:

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

Extract and enter the source directory:

tar -xf nginx-1.14.1.tar.gz
cd nginx-1.14.1

Modify the C source files to set a custom header:

Edit src/http/ngx_http_header_filter_module.c (line 49) and replace the default string with:

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

Edit src/http/ngx_http_special_response.c (line 36) and add the same string wrapped in HTML: "<hr><center>Please guess it!</center>" \r\n Configure, compile, and install Nginx:

./configure --prefix=/usr/local/nginx
make && make install

Update the main configuration to turn off the default server token:

vim /usr/local/nginx/conf/nginx.conf
# inside the http block add:
server_tokens off;

Start Nginx: /usr/local/nginx/sbin/nginx Verify the custom header:

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

Browser access shows the same custom header (screenshot omitted for brevity).

Notes:

If you only want to hide the version number without a custom header, skip the source‑code modifications (step 3).

When upgrading Nginx, you can apply the same modifications before running ./configure and make.

For detailed upgrade instructions, refer to the linked blog post.

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.

ConfigurationLinuxNGINXWeb serverserver headerVersion Hiding
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
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.