apache調優隱藏版本資訊及404重新導向

來源:互聯網
上載者:User

標籤:

生產環境中,部署了apache之後,我們應該從安全還是效能角度,在apache服務上線之前,對其做諸多的最佳化調試才行。

 

Apache

實驗環境:

apache版本:httpd-2.2.31

源碼包存放位置:/usr/local/src

源碼包編譯安裝位置:apache:/usr/local/apache2.2-xuegod/

 

技巧1:

安裝apache屏蔽apache版本等敏感資訊

 

查看apache版本資訊:

[[email protected]yeyou ~]# curl -Iwww.baidu.com

。。。

X-Powered-By: HPHP

Server: BWS/1.1

X-UA-Compatible:IE=Edge,chrome=1

BDPAGETYPE: 1

BDQID: 0xcfd31d8200026e11

BDUSERID: 0

 

測試自己的網站看是什麼版本?有沒有相應的漏洞

 

[[email protected]yeyou ~]# curl -Iwww.taobao.com

HTTP/1.1 302 Found

Server:Tengine  基於nginx做了二次開發

Date: Tue, 17 Nov 201502:22:06 GMT

Content-Type: text/html

Content-Length: 258

Connection: keep-alive

Location:https://www.taobao.com/

徹底讓版本等敏感資訊消失

要徹底將版本之類的資訊進行改頭換面,需要在編譯之前修改源碼包下include/ap_release.h檔案

[[email protected]yeyou httpd-2.2.25]#pwd

/usr/local/src

[[email protected]yeyou src]# rm -rfhttpd-2.2.25

[[email protected]yeyou src]# tar zxfhttpd-2.2.25.tar.gz

[[email protected]yeyou src]# cdhttpd-2.2.25

[[email protected]yeyou httpd-2.2.25]#vim include/ap_release.h  #修改源碼中的版本資訊為自己公司的相關資訊,隱藏真實版本資訊

改:

42 #define AP_SERVER_BASEVENDOR"Apache Software Foundation"

 43 #define AP_SERVER_BASEPROJECT "ApacheHTTP Server"

 44 #define AP_SERVER_BASEPRODUCT"Apache"

 45

 46 #define AP_SERVER_MAJORVERSION_NUMBER 2

 47 #define AP_SERVER_MINORVERSION_NUMBER 2

 48 #define AP_SERVER_PATCHLEVEL_NUMBER   25

 49 #define AP_SERVER_DEVBUILD_BOOLEAN    0

為:

#defineAP_SERVER_BASEVENDOR "xuegod"

#defineAP_SERVER_BASEPROJECT " web server"

#defineAP_SERVER_BASEPRODUCT " xuegod web server"

 

#defineAP_SERVER_MAJORVERSION_NUMBER 8

#defineAP_SERVER_MINORVERSION_NUMBER 1

#defineAP_SERVER_PATCHLEVEL_NUMBER   2

#defineAP_SERVER_DEVBUILD_BOOLEAN    3

注釋:

#define AP_SERVER_BASEVENDOR"Apache Software Foundation" #服務的供應商名稱

#define AP_SERVER_BASEPROJECT"Apache HTTP Server"  #服務的項目名稱

#define AP_SERVER_BASEPRODUCT"Apache"        #服務的產品名

#define AP_SERVER_MAJORVERSION_NUMBER2  #主要版本號碼

#defineAP_SERVER_MINORVERSION_NUMBER 4  #小版本號碼

#defineAP_SERVER_PATCHLEVEL_NUMBER  6  #補丁層級

#defineAP_SERVER_DEVBUILD_BOOLEAN  0  #

註:上述列出的行,大家可以修改成自己想要的,然後編譯安裝之後,再對httpd-default.conf檔案進行修改,對方就徹底不知道你的版本號碼了。

源碼編譯安裝apache

[[email protected]yeyou httpd-2.2.11]# yum installopenssl*

[[email protected]yeyou httpd-2.2.25]#./configure --prefix=/usr/local/apache2.2-xuegod --enable-so --enable-rewrite--enable-ssl   --enable-deflate  --enable-expires   #檢查安裝環境並產生Makefile檔案

 

配置參數用途:

--prefix=/usr/local/apache2.2   #指定安裝路徑

--enable-so  # 支援動態載入模塊

--enable-rewrite #支援網站地址修正

--enable-ssl # 支援ssl加密

--enable-deflate #支援頁面傳輸前進行壓縮

--enable-expires #支援設定網頁緩衝的時間

 

編譯安裝:make&& make install

 

查看安裝後目錄:

[[email protected]yeyou httpd-2.2.25]# ls/usr/local/apache2.2-xuegod/conf/httpd.conf

/usr/local/apache2.2-xuegod/conf/httpd.conf

存放網站的根目錄:

[[email protected]yeyou httpd-2.2.25]#ls /usr/local/apache2.2-xuegod/htdocs/

index.html

修改預設首頁內容:

[[email protected]yeyou httpd-2.2.25]# echo apache-xuegod>> /usr/local/apache2.2-xuegod/htdocs/index.html

啟動apache:

配置apache 可以開機啟動並且可以使用service 命令啟動apache伺服器

[[email protected] httpd-2.2.25]#cp /usr/local/apache2.2-xuegod/bin/apachectl /etc/init.d/apachectl-xuegod

 

啟動apache:

[[email protected]2.25]# /etc/init.d/apachectl-xuegod start

 

測試:隱藏apache版本資訊

curl -I192.168.1.63   #看不到apache版本相關內容了

HTTP/1.1 200 OK

Date: Sat, 29 Aug 201509:43:44 GMT

Server: xuegod web server/8.1.2-dev (Unix) mod_ssl/8.1.2-devOpenSSL/1.0.0-fips

Last-Modified: Sat, 29 Aug2015 09:37:36 GMT

ETag: "6d086-3a-51e6ff35dba19"

Accept-Ranges: bytes

Content-Length: 58

Content-Type: text/html

 

再次隱藏版本號碼和系統類別型

接下來再次修改:

 

vim/usr/local/apache2.2-xuegod/conf/httpd.conf

405 #Includeconf/extra/httpd-default.conf

為:

Includeconf/extra/httpd-default.conf

 

2)開啟httpd-default.conf檔案,修改如下兩個地方

vim/usr/local/apache2.2-xuegod/conf/extra/httpd-default.conf 

改:

55 ServerTokens Full

65 ServerSignature On    signature 簽名

為:

ServerTokens Prod   #不顯示伺服器作業系統類型

ServerSignature Off   #不顯示web伺服器版本號碼

 

讓apache設定檔生效的方法:

方法1:重啟服務:restart      

方法2:不重啟服務,重新載入設定檔

reload是nginx

/etc/init.d/apachectl-xuegod graceful     優雅的

測試:

curl -I192.168.1.63

HTTP/1.1 200 OK

Date: Thu, 14 Jan 201602:31:24 GMT

Server: xuegod web server

 

總結:

1,  安裝之前改include/ap_release.h

2,  Httpd.conf    extra/httpd-default.conf去掉注釋

3,  修改extra/httpd-default.conf

55 ServerTokens Full

65 ServerSignature On    signature 簽名

為:

ServerTokens Prod   #不顯示伺服器作業系統類型

ServerSignature Off   #不顯示web伺服器版本號碼

 

2、錯誤頁面優雅顯示

為了提升網站的使用者體驗,避免404,403之類的醜陋的預設錯誤提示出現。

http://192.18.1.63/a.html

 

方法一:

vim/usr/local/apache2.2-xuegod/conf/httpd.conf  #在根目錄的標籤中添加以下紅色標記內容。

132 <Directory"/usr/local/apache2.2-xuegod/htdocs">

。。。

在大約159行,插入:

     ErrorDocument 404 /404.html

160 </Directory>

註:#將404錯誤跳轉到/usr/local/apache2.2-xuegod/htdocs下的404.html頁面上

註:ErrorDocument的命令格式如下:

ErrorDocument 錯誤碼 跳轉到的頁面連結或檔案

 

建立404測試頁:

echo"404 go to home" > /usr/local/apache2.2-xuegod/htdocs/404.html

 

重啟:

/etc/init.d/apachectl-xuegodrestart

 

 

方法2: 出錯後,跳轉到一個連結

vim/usr/local/apache2.2-xuegod/conf/httpd.conf  #在根目錄的標籤中添加以下紅色標記內容。

132 <Directory"/usr/local/apache2.2-xuegod/htdocs">

。。。

在大約159行,插入:

     ErrorDocument 404 http://www.baidu.com

160 </Directory>

註:#將404錯誤跳轉到http://www.baidu.com

 

重啟:

/etc/init.d/apachectl-xuegod restart

apache調優隱藏版本資訊及404重新導向

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.