源碼編譯安裝:隱藏nginx的版本信息

1)首先要下載nginx包這裏以1.12.2爲例;

2)安裝nginx所需的支持包

yum install -y gcc gcc-c++ pcre-devel zlib-devel

3)創建nginx用戶

useradd -M -s /sbin/nologin nginx

4)解壓nginx並配置

tar zxf nginx-1.12.2.tar.gz

①vi src/core/nginx.h    13行     
          #define nginx_version      1010002
      #define NGINX_VERSION      "6.12.62"         #此行修改的是你想要的版本號
      #define NGINX_VER          "MidServer/" NGINX_VERSION    
                                                                   #此行修改的是你想修改的軟件名稱

            ![](https://s1.51cto.com/images/blog/201901/08/dcb7f60989243494cb5e2351d441433f.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

            ②# vim src/http/ngx_http_special_response.c    29行

      #static u_char ngx_http_error_tail[] =
      "<hr><center>MidServer</center>" CRLF
       "</body>" CRLF
       "</html>" CRLF

                ![](https://s1.51cto.com/images/blog/201901/08/d987ac49b6e40902f928e25f5d6f6cb5.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

5)yum -y install pcre openssl

  cd  nginx-1.12.2/

        # ./configure --prefix=/usr/local/nginx   --user=nginx --group=nginx \

--with-file-aio \
--with-http_ssl_module \
--ith-http_realip_module \
--ith-http_sub_module \
--ith-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre

make && make install

6)安裝完後我們啓動服務

 

/usr/local/nginx/sbin/nginx 啓動服務

/usr/local/nginx/sbin/nginx -s stop 停止服務

 

測試是否隱藏了版本和軟件名

 # curl -I 192.168.80.100
HTTP/1.1 200 OK
Server: MidServer/6.12.62
Date: Tue, 08 Jan 2019 07:36:11 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 08 Jan 2019 07:34:45 GMT
Connection: keep-alive
ETag: "5c345295-264"
Accept-Ranges: bytes

 

我們拿瀏覽器進行錯誤代碼測試:
源碼編譯安裝:隱藏nginx的版本信息

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章