阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 14.04 下安装Apache+ModSecurity

111次阅读
没有评论

共计 2300 个字符,预计需要花费 6 分钟才能阅读完成。

平台:Ubuntu 14.04

第一步:安装 apache

我建议安装 Apache 最好用 apt-get 安装,这样就可以少很多的库支持!!!!如果不嫌麻烦的话可以用源码安装

输入 apt-get install apache2

如果提示没有这个软件包就更新一下软件包 apt-get install update

这步安装好了以后 apache 就可以提供服务了,输入 127.0.0.1 就可以访问本地网站了

第二步:安装 modsecurity

这个也和上边的一样,使用

apt-get install libxml2 libxml2-dev libxml2-utils libaprutil1 libaprutil1-dev libapache2-modsecurity

安装好了以后就可以查看你的 modsecurity 的版本号是多少,使用

dpkg -s libapache2-modsecurity | grep Version

第三步 配置 modsecurity

service apache2 reload

该命令生效后,会在 /var/log/apache2/ 目录下生成 modsecurity 的日志文件 modsec_audit.log

使用 modsecurity 核心规则集

将我们想起用的规则集放置在以下目录下

cd /usr/share/modsecurity-crs/activated_rules/

选择启用 base 规则集

for f in $(ls ../base_rules/); do ln -s ../base_rules/$f; done

修改 apache 模块配置,启用规则集

注意:modsecurity 2.7 版本与 2.6 版本的配置文件有些区别

(1)2.7 版本
vim /etc/apache2/mods-available/security2.conf

修改
<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       
IncludeOptional /usr/share/modsecurity-crs/*.conf       
IncludeOptional /usr/share/modsecurity-crs/activated_rules/*.conf
</IfModule>

(2)2.6 版本
‍‍vim  /etc/apache2/mods-available/mod-security.conf‍‍

修改
Include /etc/modsecurity/*.conf
Include /usr/share/modsecurity-crs/*.conf
Include /usr/share/modsecurity-crs/activated_rules/*.conf

启动 modsecurity 模块

a2enmod headersa2enmod security2 (版本 2.6:a2enmod mod-security)service apache2 restart

注意!!!!!!!!!!!!!!
一旦这样修改了以后,使用 IP 地址就显示 403 错误!!!!!!为了这个错误,搞了一天,在网上搜各种 403 错误就是不行,为什么呢????
查看 errol.log 就可以发现,是 modsecurity 里面禁止了使用 IP 访问!!!!!!使用 localhost 就可以正常访问了。。。
所以,看日志是一个很重要的事儿

————————————- 我是分割线 ————————————-

Ubuntu 下 Apache 的 Rewrite 如何启用  http://www.linuxidc.com/Linux/2010-10/29027.htm

Ubuntu 14.04 中 Apache 2.2 升级到 2.4 后的几个要点 http://www.linuxidc.com/Linux/2015-01/111914.htm

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2300字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中