隐藏Nginx标识与版本号
前言
为什么要隐藏nginx标识与版本号?因为nginx默认配置存在安全漏洞。如下图:

目录
1、隐藏版本号
2、隐藏Nginx标识--修改源码
3、重新编译安装后即可
1、隐藏版本号
curl Nginx服务器时,有这么一行Server: nginx,说明我用的是 Nginx 服务器,但并没有具体的版本号。由于某些 Nginx 漏洞只存在于特定的版本,隐藏版本号可以提高安全性。这只需要在nginx.conf配置里加上这个就可以了:
编辑server模块在server_name下面怎么如下配置:
server_tokens off;
eg:

2、隐藏Nginx标识--修改源码
下载Nginx源码 http://nginx.org/download/nginx-1.19.2.tar.gz
下载不同版本的nginx模板
http://nginx.org/download/nginx-填写版本号.tar.gz
下载后存放位置:
[图片上传失败...(image-8211aa-1614592774731)]
2.1第一步:修改 core包下的nginx.h文件**
vim src/core/nginx.h +14
#define NGINX_VER "happy/" NGINX_VERSION
修改前:

修改后:
[root@glxxh src]# vim core/nginx.h

2.2第二步:修改src/http包下文件
修改文件:
1.ngx_http_special_response.c
2.ngx_http_header_filter_module.c
2.2.1修改gx_http_special_response.c
# vim src/http/ngx_http_special_response.c +22 +29 和 +36 (注意修改后无引号,NGINX_VER为变量)
修改前:

修改后

"
<center>happy</center>" CRLF
2.2.2修改ngx_http_header_filter_module.c:
# vim src/http/ngx_http_header_filter_module.c +49
修改为:

static char ngx_http_server_string[] = "Server: happy" CRLF;
3、重新编译安装后即可
3.1第一步:先备份
先备份/usr/local/nginx/sbin下的启动文件
再备份/usr/local/nginx/conf/下的nginx.conf文件
3.2第二步:编译nginx源码

进入nginx目录进行编译操作
cd nginx-1.13.7
[root@localhost nginx-1.13.7]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.13.7]# make
3.3第三步:更换启动文件nginx(非常重要的一步):
1.先停掉nginx服务器:
2.备份/usr/local/nginx/sbin/nginx文件
3.替换启动文件:将编译好的/u sr/local/nginx-1.13.7/objs/nginx 拷贝到/usr/local/nginx/sbin/下
4.启动nginx
[root@localhost sbin]# ./nginx -V
4、curl -I localhost

5、访问验证
修改前:

修改后:

6.修改默认配置
/usr/local/nginx/html下面的静态页面要修改不要出现nginx的字样。

如果遇到这方面的问题,没有处理好,请留言,如果有写的不对的地方请指正。
网友评论