zoukankan      html  css  js  c++  java
  • 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 

  • 相关阅读:
    HDU 4081 Peach Blossom Spring (最小生成树+dfs)
    查看u盘格式
    eclipse使用外部maven时multiModuleProjectDirectory错误解决
    Centos更换yum源,安装ssh server
    gerrit push配置
    netstat
    java多维数组
    RESTful架构3--开发实战
    RESTful架构2--架构详解
    RESTful架构1--架构理解
  • 原文地址:https://www.cnblogs.com/Sunzz/p/9962891.html
Copyright © 2011-2022 走看看