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.
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.gzExtract and enter the source directory:
tar -xf nginx-1.14.1.tar.gz
cd nginx-1.14.1Modify 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 installUpdate 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
...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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
