为什么要隐藏 Nginx 版本号和软件名:一般来说,软件的漏洞都与版本有关,隐藏版本号是为了防止恶意用户利用软件漏洞进行攻击,而软件名可以进行修改,否则黑客知道是 Nginx 服务器更容易进行攻击,需要注意的是,隐藏 Nginx 软件名需要重新编译安装 Nginx ,如果没有该方面需求尽量不要做

1、修改:/usr/local/src/nginx-1.6.3/src/core/nginx.h

#define NGINX_VERSION      "8.8.8.8"                  # 修改为想要显示的版本号#define NGINX_VER          "Google/" NGINX_VERSION    # 修改为想要显示的软件名#define NGINX_VAR          "Google"                   # 修改为想要显示的软件名

2、修改:/usr/local/src/nginx-1.6.3/src/http/ngx_http_header_filter_module.c

static char ngx_http_server_string[] = "Server: Google" CRLF;           # 修改为想要显示的软件名static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;

3、修改:/usr/local/src/nginx-1.6.3/src/http/ngx_http_special_response.c

隐藏 Nginx 版本号和软件名 _NGINX 调优

static u_char ngx_http_error_full_tail[] =
"<hr><center>" NGINX_VER "(www.google.com)</center>" CRLF    # 此行定义对外展示的内容"</body>" CRLF
"</html>" CRLF
;


static u_char ngx_http_error_tail[] =
"<hr><center>Google</center>" CRLF       # 此行定义对外展示的软件名"</body>" CRLF
"</html>" CRLF
;

隐藏 Nginx 版本号和软件名 _NGINX 调优

4、重新编译 Nginx 

cd /usr/local/src/nginx-1.6.3./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx