隐藏或者更改nginx版本号

隐藏nginx版本
1.首先查看下本机nginx版本信息为nginx1.18
[root@scyun ~]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.18.0  #版本为nginx 1.18.0
Date: Thu, 17 Dec 2020 08:12:28 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 17 Dec 2020 08:10:03 GMT
Connection: keep-alive
ETag: "5fdb125b-264"
Accept-Ranges: bytes
2.隐藏nginx版本号
[root@scyun ~]# vim /usr/local/nginx/conf/nginx.conf #编辑.conf配置文件

server_tokens off;  #在http模块或者server添加
3.重新加载文件验证
[root@scyun ~]# nginx -s reload
[root@scyun ~]# !curl    ####curl -I 127.0.0.1
curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx #版本号已经隐藏了
Date: Thu, 17 Dec 2020 08:20:32 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 17 Dec 2020 08:10:03 GMT
Connection: keep-alive
ETag: "5fdb125b-264"
Accept-Ranges: bytes
修改nginx版本(源码部署)
1.修改源码部署的nginx需要重新编译,需修改源文件代码
[root@scyun nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@scyun nginx-1.18.0]# vim src/core/nginx.h 

#define NGINX_VERSION      "2.18.0"  #修改版本号
#define NGINX_VER          "SCSW/" NGINX_VERSION #名称
[root@scyun nginx-1.18.0]# nginx -V #查看之前编译添加的参数有哪些,把之前添加的在重新添加预编译
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --prefix=/usr/local/nginx #只指定一个目录
[root@scyun nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/

[root@scyun nginx-1.18.0]# make && make install #执行编译/安装
[root@scyun nginx-1.18.0]# make upgrade #执行升级
2.验证更改版本号
[root@scyun nginx-1.18.0]# !curl   ###curl -I 127.0.0.1
curl -I 127.0.0.1 
HTTP/1.1 200 OK
Server: SCSW/2.18.0
Date: Thu, 17 Dec 2020 08:40:00 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 17 Dec 2020 08:10:03 GMT
Connection: keep-alive
ETag: "5fdb125b-264"
Accept-Ranges: bytes
#如果这里还没看到更改的版本号,请检查nginx.conf文件中server_tokens off/on; 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

亦读

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

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

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

打赏作者

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

抵扣说明:

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

余额充值