前言
現今我們在Ubuntu 16.04上面安裝的Apache2在預設的使用下,會回傳Server的回應標頭。
當我們使用如curl等指令時,會得到如下的相關資訊:
1 | curl -I your-domain.com | grep Server |
1 | Server: Apache /2 .4.18 (Ubuntu) |
如上這樣情形,會因此造成資訊洩漏,讓其他有心人士可以透過回應的標頭猜測出網站相關的訊息。為了防止這個情況的方式,我們需要安裝security2模組與設定。來隱藏這個訊息。
預先安裝的環境
我們使用的預先安裝環境的系統發行版本與Apache2版本為下列列表:
1 2 3 | Ubuntu 16.04 Apache /2 .4.18 |
安裝mod_security2
透過下面的指令,把mod_security2安裝起來
1 2 3 | sudo apt-get update sudo apt-get install libapache2-mod-security2 |
編輯mod_security2設定檔
1 | sudo vim /etc/apache2/mods-enabled/security2 .conf |
見到下面的設定檔,在裡面加上一行(設定檔中有標注)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <IfModule security2_module> # Default Debian dir for modsecurity's persistent data SecDataDir /var/cache/modsecurity # Include all the *.conf files in /etc/modsecurity. # Keeping your local configuration in that directory # will allow for an easy upgrade of THIS file and # make your life easier IncludeOptional /etc/modsecurity/ *.conf # 加入下面那一行 SecServerSignature " " < /IfModule > |
重啟Apache2服務
依照先前的設定檔完成之後,下面跟著執行指令來重啟Apache2服務
1 | sudo service apache2 restart |
驗證Server回應標頭
我們再使用下面cURL指令來驗證回應標頭是否正確。
1 | curl -I your-domain.com | grep Server |
這時候就會發現改成下面的回應標頭了!
1 | Server: |