nginx 隐藏版本号与WEB服务器信息

nginx不仅可以隐藏版本信息,还支持自定义web服务器信息

先看看最终的隐藏结果吧

具体怎么实现呢,其实也很简单,请往下看

 

1 官网下载最新稳定版

wget  http://nginx.org/download/nginx-1.14.1.tar.gz

2 解压

tar -xf nginx-1.14.1.tar.gz
cd nginx-1.14.1

3 修改C文件
(1)vim src/http/ngx_http_header_filter_module.c               #修改49行
static u_char ngx_http_server_string[] = "Server: Please guess it!" CRLF;    #Server后写上你自定义的服务器信息

(2)vim src/http/ngx_http_special_response.c      #修改36行
"<hr><center>Please guess it!</center>" CRLF    #再写一遍刚才的字符串

4 编译配置

./configure --prefix=/usr/local/nginx

5 编译安装

make && make install

6 修改nginx配置文件,http节点下添加 server_tokens off
vim /usr/local/nginx/conf/nginx.conf
....
http {
server_tokens off;
.....

 7 启动nginx

/usr/local/nginx/sbin/nginx

8 测试

[root@node1 nginx-1.14.1]# curl -I http://127.0.0.1
    HTTP/1.1 200 OK
    Server: Please guess it!
    Date: Wed, 07 Nov 2018 19:15:43 GMT
  ......

浏览器访问测试

  

 

说明:(1)要是只想隐藏版本号,而不想自定义服务器信息,不需要执行第3步.
     (2)要是对nginx升级同时还要做字符串自定义,也是没有问题的,可以先修改C文件-->./configure --> make 即可

     具体nginx升级请参考 https://www.cnblogs.com/Sunzz/p/9953443.html 

转载于:https://www.cnblogs.com/Sunzz/p/9962891.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值