前言
要让Nginx隐藏版本号及软件名称,这还要从源码包开刀,也就是在安装前,修改Nginx源码包中的一些参数,以到达安装时软件名称及版本号都为我们指定内容,进而达到效果。
执行流程
注:此案例中Nginx为1.2.9版本,可转到==>http://nginx.org/download/nginx-1.2.9.tar.gz下载
1.安装nginx依赖包
yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel make automake
2.修改nginx.h文件
解压Nginx
tar xf nginx-1.2.9.tar.gz
cd nginx-1.2.9/
修改nginx.h文件
vim /src/core/nginx.h
第13,14行就是我们的目标
这两项分别是nginx的版本号和服务器名称,可随意更改,达到效果即可。
3.修改ngx_http_header_filter_module.c文件
此文件可以设置HTTP报文的头部,修改的目的是防止回显具体的Web软件
vim src/http/ngx_http_header_filter_module.c
在第49行
其中的nginx就是Web软件名称,将其修改
4.修改ngx_http_special_response.c文件
这个文件定义了http错误码的返回信息,当页面出错时,nginx会返回相应的错误代码,并显示Web软件名称及版本号。
vim src/http/ngx_http_special_response.c
在29行
将其中的nginx修改即可
预编译,安装
创建运行账户及组
groupadd www
useradd -M -s /sbin/nologin/ -g www www
预编译
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
编译,安装
make && make install
启动nginx
/usr/local/nginx/sbin/nginx
测试
查看nginx版本及软件名称
curl -I 192.168.1.123
HTTP/1.1 200 OK
Server: Web/233.233.233
Date: Sun, 19 Jul 2020 08:13:07 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 19 Jul 2020 08:09:43 GMT
Connection: keep-alive
Accept-Ranges: bytes
可以看到,在Server项中,软件名及版本已经更改
在浏览器中输入错误的网页测试,返回结果也更改成功了。