Centos 7.2 安装modsecurity (for apache)

1.安装mod_security所需套件

# yum install gcc make httpd-devel libxml2 pcre-devel libxml2-devel curl-devel git

2.下载mod_security源码进行编译安装

(1)下载稳定版本安装

# wegt https://www.modsecurity.org/tarball/2.9.0/modsecurity-2.9.0.tar.gz

# tar xzf modsecurity-2.9.0

# cd modsecurity-2.9.0

# ./configure

# make install

# cp modsecurity.conf-recommended  /etc/httpd/conf.d/modsecurity.conf

# vi modsecurity.conf

(将SecRuleEngine DetectionOnly改为SecRuleEngine On)

# cp unicode.mapping /etc/httpd/conf.d/

(2)从git获取新版本下载

# git clone git://github.com/SpiderLabs/ModSecurity.git

#git checkout remotes/trunk

--------------------------------------------------------------------------------------------------------(或者自己下载到windows再ftp一份)

# cd modsecurity

# ./autogen.sh

( 这里如果报错,./autogen.sh:line 11:libtoolize: command not found等等

解决办法是:yum -y install libtool)

# ./configure

# make

# make install

$cp /usr/local/modsecurity/lib/mod_security2.so /etc/httpd/modules/

# cp modsecurity.conf-recommended  /etc/httpd/conf.d/modsecurity.conf

# vi modsecurity.conf

(将SecRuleEngine DetectionOnly改为SecRuleEngine On)

3.配置规则(使用推荐的OWASP)

# cd /etc/httpd

# git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git

# mv owasp-modsecurity-crs modsecurity-crs

# cd modsecurity-crs

# cp modsecurity_crs_10_set_up.conf.example modsecurity_crs_10_config.conf

4. 修改配置文件并重启apache。

# vi /etc/httpd/conf/httpd.conf

(在其中加入以下几行)

LoadModule security2_module modules/mod_security2.so

       Include /etc/httpd/modsecurity-crs/modsecurity_crs_10_config.conf

       Include /etc/httpd/modsecurity-crs/rules/*.conf

其中写入配置文件的时候注意路径是否一致。

5.重启apache就完了。

 

卸载modsecurity

1. 删除/etc/httpd/conf.d/modsecurity.conf

2.修改:/etc/httpd/conf/http.conf删除之前添加的内容

3.删除/usr/lacal/modsecurity的编译文件

你可能感兴趣的:(modsecurity)