隐藏 Nginx 版本号和软件名

隐藏nginx版本号:

首先,为什么要隐藏版本号?

  因为一般来说,软件的漏洞都与版本有关,隐藏版本号是为了防止恶意用户利用软件漏洞进行攻击。

查看服务器响应的头部信息(查看是否隐藏版本号和软件名):
[root@nginx51 ~]# curl -I http://localhost/ ##curl – -I

进入 /usr/local/nginx/conf/nginx.conf

再http的行内写入一条 ” server_tokens off; “即可

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;      #隐藏版本号
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

   #access_log  logs/access.log  main;

   sendfile        on;
    #tcp_nopush     on;

   #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

隐藏版本号前:
HTTP/1.1 200 OK
Server: nginx/1.12.2 ##显示了版本号
Date: Thu, 08 Nov 2018 08:05:22 GMT
Content-Type:text/html
Content-Length: 612
Last-Modified:Thu, 08 Nov 2018 07:32:55 GMT
Connection: keep-alive
ETag: “5be3e6a7-264”
Accept-Ranges: bytes
《隐藏 Nginx 版本号和软件名》

隐藏版本号后:
HTTP/1.1 200 OK
Server: nginx ##不显示版本号
Date: Thu, 08 Nov 2018 08:05:39 GMT
Content-Type:text/html
Content-Length: 612名
Last-Modified:Thu, 08 Nov 2018 07:32:55 GMT
Connection: keep-alive
ETag: “5be3e6a7-264”
Accept-Ranges: bytes
《隐藏 Nginx 版本号和软件名》

修改软件名:

为什么要修改软件名?

因为黑客知道是 Nginx 服务器后更容易进行攻击,需要注意的是,修改 Nginx 软件名需要重新编译安装 Nginx ,如果没有该方面需求尽量不要做

cd进入nginx的源码包目录后
[root@nginx51 ~]# cd /root/nginx-1.12.2/

[root@nginx51 nginx-1.12]# vim +48 src/http/ngx_http_header_filter_module.c
//注意:vim这条命令必须在nginx-1.12源码包目录下执行,+48的意思是vim进入后直接调转再第48行

找到这三行更改为
static u_char ngx_http_server_full_string[] = “Server:”NGINX_VER CRLF;

《隐藏 Nginx 版本号和软件名》

    原文作者:wgw_memory
    原文地址: https://blog.csdn.net/wgw_dream/article/details/83867597
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞