Nginx是轻量化、高性能的Web server软件,其占用低,并发能力强等等,受到很多人的欢迎。但是随之而来的各种机器人扫描器,倘若伪装成其他的web服务器,这里也可以欺骗一下扫描器等等这些东西,防君子不防小人。
以下修改需要下载Nginx编译包解压并需要在以下文件中修改,修改后进行编译安装。
src/core/nginx.h
#define NGINX_VER "nginx/" NGINX_VERSION//修改为#define NGINX_VER "NEWS/" NGINX_VERSION#define NGINX_VAR "NGINX"//修改为#define NGINX_VAR "NEWS"
src/http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;//修改为static u_char ngx_http_server_string[] = "Server: NEWS" CRLF;
src/http/ngx_http_special_response.c
"<hr><center>nginx</center>" CRLF//修改为"<hr><center>NEWS</center>" CRLF
src/http/v2/ngx_http_v2_filter_module.c
"http2 output header: \"server: nginx\"");//修改为"http2 output header: \"server: NEWS\"");
通过修改上面4个文件,我们已将nginx服务器名修改为了NEWS
,如果不想去找到文件一个一个修改,也可以使用sed
命令直接替换:
#执行更名操作sed -i "s#\"NGINX\"#\"NEWS\"#" src/core/nginx.hsed -i "s#\"nginx/\"#\"NEWS/\"#" src/core/nginx.hsed -i "s#Server: nginx#Server: NEWS#" src/http/ngx_http_header_filter_module.csed -i "s#\"<hr><center>nginx<\/center>\"#\"<hr><center>NEWS<\/center>\"#" src/http/ngx_http_special_response.csed -i "s#server: nginx#server: NEWS#"