nginx隐藏标识与版本号 | 您所在的位置:网站首页 › nginx屏蔽版本号 › nginx隐藏标识与版本号 |
隐藏Nginx标识与版本号前言 为什么要隐藏nginx标识与版本号?因为nginx默认配置存在安全漏洞。如下图: image.png 目录1、隐藏版本号 2、隐藏Nginx标识--修改源码 3、重新编译安装后即可 1、隐藏版本号curl Nginx服务器时,有这么一行Server: nginx,说明我用的是 Nginx 服务器,但并没有具体的版本号。由于某些 Nginx 漏洞只存在于特定的版本,隐藏版本号可以提高安全性。这只需要在nginx.conf配置里加上这个就可以了: 编辑server模块在server_name下面怎么如下配置: server_tokens off; eg: image.png 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修改前: image.png 修改后: [root@glxxh src]# vim core/nginx.h image.png 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为变量)修改前: image.png 修改后 image.png " happy" CRLF 2.2.2修改ngx_http_header_filter_module.c:# vim src/http/ngx_http_header_filter_module.c +49修改为: image.png 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源码image.png 进入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 localhostimage.png 5、访问验证修改前: image.png 修改后: image.png 6.修改默认配置/usr/local/nginx/html下面的静态页面要修改不要出现nginx的字样。 image.png 如果遇到这方面的问题,没有处理好,请留言,如果有写的不对的地方请指正。 |
CopyRight 2018-2019 实验室设备网 版权所有 |