mods 是apache的一個安全模塊,他的做用是web應用防火牆(WAF).若是不懂WAF請自行google下。git
mods在yum源(centos)以及apt源(ubuntu)下都有現成的安裝包。只須要相似 apt-get install 或者yum install 便可。
可是在mac的osx系統下,沒有任何二級制安裝包,若是想在osx上玩mods,那就須要從源碼編譯github
通常來講,一條命令就能夠搞定。誰讓brew很逆天呢。
命令以下:web
brew install homebrew/apache/mod_security
參考:https://gist.github.com/amarn...apache
若是順利的話,brew會下載全部依賴以及mods的源碼進行編譯安裝。可是....貌似通常不會那麼順利。ubuntu
解決方案: sudo chown ${whoami} /usr 直接暴力把/usr的歸屬給變成了當前用戶..哪位大佬有其餘方案請分享出來vim
解決方案:centos
brew會顯示從那個url下載該源碼包。複製url,瀏覽器下載xcode
而後執行brew --cache看看cache目錄在哪裏瀏覽器
把下載下來的壓縮包丟到該目錄下面(奇怪的是我這邊顯示出來的cache目錄不是顯示出來的cache目錄,你們能夠往/Users/xxx/Library/Caches/Homebrew/放一份再)安全
這個有點麻煩,理論上brew會幫忙裝好的。可是我看日誌好像是mods的makefile指定的apr/apu的目錄有問題,修改makefile有點麻煩,又不知道brew把apr和apu裝到哪裏去了。因此本身下載apr和apu的安裝包,再編譯了一遍,而後./configration的時候經過參數指定路徑。參考
xcode-select --install
我以前就關閉了,雖然是一個不錯的安全策略,可是對開發者很不方便。
具體關閉步驟:
重啓機器,在啓動的時候長按command+R,進入恢復模式
打開terminal,執行
csrutil disable
重啓機器到正常模式
編譯方式以下:(請使用sudo -i 切換到root用戶下)
./configure --prefix=/usr/local/Cellar/mod_security/2.9.1 --with-pcre=/usr/local/opt/pcre --with-apxs=/usr/sbin/apxs --with-apr=/usr/local/apr/bin/apr-1-config --with-apu=/usr/local/apr/bin/apu-1-config
在解壓目錄下執行 make
在解壓目錄下執行 make install
請檢查/usr/local/Cellar/mod_security/2.9.1/lib
下是否有mod_security2.so
,如有則標識編譯成功
進行模塊配置
1. vim /etc/apache2/httpd.conf 2. 配置載入模塊: LoadModule security2_module /usr/local/Cellar/mod_security/2.9.1/lib/mod_security2.so 3. 從源碼目錄複製配置文件到指定文件夾 cp modsecurity.conf-recommended /etc/apache2/other/modsecurity.conf
sudo apachectl start