源码安装的Nginx隐藏版本防止泄露版本信息

1.修改Nginx的源码
#查看版本信息
/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

#切换Nginx目录
cd /root/nginx-1.18.0

#查看Nginx目录
ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

#清除编译信息,因为之前编译过
make clean

#查看清除编译信息后Nginx目录,少了Makefile文件 、objs 目录
 ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

#修改源码软件名称和版本信息
sed -i "s#\#define NGINX_VERSION      \"1.18.0\"#\#define NGINX_VERSION      \"8.8.0\"#g"  /root/nginx-1.18.0/src/core/nginx.h
sed -i "s#\#define NGINX_VER          \"nginx/\" NGINX_VERSION#\#define NGINX_VER          \"Web/\" NGINX_VERSION#g" /root/nginx-1.18.0/src/core/nginx.h

2.修改Nginx的头部信息(headers)

#在开发者模式,查看Nginx的头部信息
在这里插入图片描述

#替换connection字段
sed -i "s#static u_char ngx_http_server_string\[\] = \"Server: nginx\" CRLF;#static u_char ngx_http_server_string\[\] = \"Server: Web\" CRLF;#g"  /root/nginx-1.18.0/src/http/ngx_http_header_filter_module.c

3.重新编译Nginx
#停掉Nginx
/usr/local/nginx/sbin/nginx -s stop

#强制删除Nginx目录
 rm -rf /usr/local/nginx/

#切换到解压的Nginx目录
cd /root/nginx-1.18.0

#检查编译环境
./configure --prefix=/usr/local/nginx   --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module  --with-http_gzip_static_module  --with-pcre 
 
 #编译Nginx源包和安装Nginx源包
make && make install

#赋予所属用户和所属用户组
chown -R nginx:nginx /usr/local/nginx/

#启动Nginx服务
/usr/local/nginx/sbin/nginx
#查看版本信息
/usr/local/nginx/sbin/nginx -v
nginx version: Web/8.8.0

#查看头部信息和返回错误页面信息
curl -i -X  head  172.25.0.20
HTTP/1.1 400 Bad Request
Server: Web/8.8.0
Date: Sun, 24 May 2020 16:11:43 GMT
Content-Type: text/html
Content-Length: 154
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>Web/8.8.0</center>
</body>
</html>

#查看错误页面的信息
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路来了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值