Nginx入门之安全优化--隐藏版本号的两种办法

Nginx 下载地址 :https://pan.baidu.com/s/1Vo5mtRB4HE_EcsjcJCuLdw

实验环境:

主机 IP
centos7.5 192.168.116.133
   

步骤

# curl -I http://192.168.116.133
//检查版本的命令

10814213622

  这样就给人家看到你的服务器nginx版本是1.12.0,Nginx有些版本有的漏洞,有些版本没有。所以这样暴露出来版本号就容易变成×××者可利用的信息。

从安全的角度来说,隐藏版本号会相对安全些!!

第一种基于配置文件

# vim /usr/local/nginx/conf/nginx.conf//编辑主配置文件
//第二十行添加
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;# service nginx reload               //重启服务# curl -I http://192.168.116.133     //再次检测

10814213834

第二种基于源代码(变更版本号和版本名使其更具有迷惑效果)

# vim /opt/nginx-1.12.0/src/core/nginx.h     //修改源码文件#define nginx_version      1012000#define NGINX_VERSION      "1.1.5"#define NGINX_VER          "IIS/" NGINX_VERSION//更改版本号,注意不用取消井号!# cd /opt/nginx-1.12.0/./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && make && make install//编译安装# vim /usr/local/nginx/conf/nginx.conf//把之前的server_tokens off;改成on# service nginx reload                   //重启服务# curl -I http://192.168.116.133     //检测结果
 

伪装成IIS服务器

10814214818

结果:

10814221639

猜你喜欢

转载自blog.51cto.com/13706064/2160027