漏洞扫描可通过HTTP获取远端WWW服务信息,需要改变HTTP服务器的缺省banner。原因是在http请求头中能看到 server 信息中nginx及版本。本文是直接更改 server 信息名称,如果只想隐藏版本 更改ngxin配置中的 server_token 为 off 即可。
先介绍一下本文原系统安装nginx 是通过 yum 安装。解决方式是通过修改nginx源码重新编译.
1、下载ngixn 安装包,可以下载最新版nginx安装包顺便把ngixn升级。查看新版nginx地址:http://nginx.org/en/download.html
cd /home
wget http://www.nginx.org/download/nginx-1.20.0.tar.gz
2、解压安装包
tar -zxvf nginx-1.20.0.tar.gz
3、修改源文件,unknow 就是你想让请求头中Server 显示的内容。
vim nginx-1.20.0/src/http/ngx_http_header_filter_module.c
4、进入解压好的nginx 安装包进行编译,只编译不安装
cd nginx-1.20.0/
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_stub_status_module
make
5、备份nginx执行文件
cp /sbin/nginx /sbin/nginxold
6、将新编译好的执行文件复制到sbin 目录,编译好的执行文件在解压安装报的 objs 目录
cp -f objs/nginx /sbin/
7、检查nginx 配置是否正确,如果有报错,查看报什么错,有可能是缺少路径,在对应路径创建目录即可
nginx -t
8、重启不能直接改变配置,需要杀死nginx进程让在重启ngixn
killall nginx
9、进如sbinx 目录,启动nginx
cd /sbin/
./nginx -s reload
10、如果启动出现下方错误执行一下命令后再执行启动命令
/sbin/nginx -c /etc/nginx/nginx.conf
11、验证是否解决问题
curl -I http://地址