Publish: 2019-08-26 | Modify: 2019-08-26
Nginx (engine x) is a high-performance HTTP and reverse proxy web server that also provides IMAP/POP3/SMTP services. XiaoZ's blog also uses Nginx as the web server. To show off, let's change the name of the Nginx server to something else.
The official download link for Nginx is http://nginx.org/en/download.html. Find the latest stable version and download the source code to your local machine.
Extract the downloaded Nginx source code and make modifications to the following files. Here, we demonstrate changing the name of the Nginx server to XCDN
.
File 1: src/core/nginx.h
#define NGINX_VER "nginx/" NGINX_VERSION
// Change to
#define NGINX_VER "xcdn/" NGINX_VERSION
#define NGINX_VAR "NGINX"
// Change to
#define NGINX_VAR "XCDN"
File 2: src/http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
// Change to
static u_char ngx_http_server_string[] = "Server: xcdn" CRLF;
File 3: src/http/ngx_http_special_response.c
"<hr><center>nginx</center>" CRLF
// Change to
"<hr><center>xcdn</center>" CRLF
File 4: src/http/v2/ngx_http_v2_filter_module.c
"http2 output header: \"server: nginx\"");
// Change to
"http2 output header: \"server: xcdn\"");
By modifying these four files, we have changed the name of the Nginx server to xcdn
. If you don't want to manually locate and modify each file, you can also use the sed
command to replace:
# Rename operation
sed -i "s#\"NGINX\"#\"xcdn\"#" src/core/nginx.h
sed -i "s#\"nginx/\"#\"xcdn/\"#" src/core/nginx.h
sed -i "s#Server: nginx#Server: xcdn#" src/http/ngx_http_header_filter_module.c
sed -i "s#\"<hr><center>nginx<\/center>\"#\"<hr><center>xcdn<\/center>\"#" src/http/ngx_http_special_response.c
sed -i "s#server: nginx#server: xcdn#"
After making the modifications, you need to recompile the source code of Nginx. The process of compiling Nginx is not described in this article, please search online for specific instructions. You can use the curl
command to test if the modification was successful. Run the command curl -I https://blog.xiaoz.org
and the returned result should show that the Server field has changed to xcdn
.
Changing the name of the Nginx server is not just for showing off, it can also provide some protection. Nginx has had vulnerabilities in the past, and changing the server name may help bypass robot scans that specifically target Nginx, thus using deception as a defense mechanism.
This article is partially based on: How to modify Nginx service internal default name to any name
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.