备注:

使用的是modsecurity 3.0 的版本,也是nginx 官方推荐使用的,同时使用的是nginx 的dynamic module

1. 环境准备

https://github.com/SpiderLabs/ModSecurity
https://github.com/SpiderLabs/ModSecurity-nginx
https://nginx.org/download/nginx-1.13.8.tar.gz
 

2.  编译libmodsecurity

a. 预备(编译依赖) 

 yum install -y pcre pcre-devel openssl openssl-devel libtool libtool-ltdl-devel gcc gcc-c++ gcc-g77 autoconf automake
geoip geip-devel libcurl libcurl-devel yajl yajl-devel lmdb-devel ssdeep-devel lua-devel
备注:比较多,实际安装会有提示 b. 编译 git clone --depth 1 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity
cd ModSecurity
git submodule init
git submodule update
./build.sh
./configure
make
make install 备注:fatal: No names found, cannot describe anything. 提示这个错误可以不用管(官方说明) c. modsecurity nginx dynamic module编译 git clone --depth 1 https://github.com/SpiderLabs/ModSecurity- nginx.git
wget https://nginx.org/download/nginx-1.13.8.tar.gz
tar xvf nginx-1.13.8.tar.gz
cd nginx-1.13.8
./configure --add-dynamic-module=../ModSecurity-nginx
make modules cp objs/ngx_http_modsecurity_module.so /usr/local/nginx/modules(此处为Nginx 安装位置,我的nginx 也是源码编译) d. nginx源码编译 参考上面的nginx下载
./configure
make
make install
 
 
3. 配置模块加载
load_module modules/ngx_http_modsecurity_module.so;
备注: 位置 nginx main
 
 
4. 测试nginx 环境准备
a.实际业务应用
/usr/local/nginx/cong/nginx.conf server {
listen localhost:8085;
location / {
default_type text/plain;
return 200 "Thank you for requesting ${request_uri}\n";
}
} b. waf(modsecurity nginx 出口,以及数据入口) nginx proxy server {
listen 80;
location / {
proxy_pass http://localhost:8085;
proxy_set_header Host $host;
}
}
 
5. modsecurity 配置文件
a. 官方模版

mkdir -p /usr/local/nginx/modsec
cd /usr/local/nginx/modsec
wget https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended
mv modsecurity.conf-recommended modsecurity.conf
启用规引擎
SecRuleEngine On
b. 创建主配置文件 main.conf
内容如下:
Include /usr/local/nginx/modsec/modsecurity.conf
SecRule ARGS:testparam "@contains test" "id:1234,deny,log,status:403" c. waf 上面的nginx 80 配置)
modsecurity on;
modsecurity_rules_file /usr/local/nginx/modsec/main.conf;
 
6. 加载配置
sbin/nginx -t
备注: 如果不报错说明没有问题,报错可以参考日志解决
 
7. 测试
实际上,上面的配置是如果请求参考testparam 包含test 就提示403

测试结果:
curl -i http://localhost/foo?testparam=dalongtest
HTTP/1.1 403 Forbidden
Server: nginx/1.13.8
Date: Sun, 18 Feb 2018 10:45:43 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive <html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.13.8</center>
</body>
</html> curl -i http://localhost/foo?testparam=dalong
HTTP/1.1 200 OK
Server: nginx/1.13.8
Date: Sun, 18 Feb 2018 10:46:14 GMT
Content-Type: text/plain
Content-Length: 47
Connection: keep-alive Thank you for requesting /foo?testparam=dalong
 
8. 扩展
同时支持 OWASP 的crs
配置参考:
wget https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/ v3.0.2.tar.gz
tar -xzvf v3.0.2.tar.gz
sudo mv owasp-modsecurity-crs-3.0.2 /usr/local
cd /usr/local/owasp-modsecurity-crs-3.0.2
sudo cp crs-setup.conf.example crs-setup.conf # Include the recommended configuration Include /usr/local/nginx/modsec/modsecurity.conf
# OWASP CRS v3 rules
Include /usr/local/owasp-modsecurity-crs-3.0.2/crs-setup.conf Include /usr/local/owasp-modsecurity-crs-3.0.2/rules/*.conf
 
 
8. 参考资料
https://github.com/SpiderLabs/ModSecurity/tree/v3/master
https://github.com/SpiderLabs/ModSecurity
https://www.nginx.com/resources/library/modsecurity-3-nginx-quick-start-guide/
 
 
 
 

modsecurity3.0 nginx 安装的更多相关文章

  1. PHP 5.5.38 + mysql 5.0.11 + zabbix3.0 + nginx 安装

    PHP 5.5.38 + mysql 5.0.11 + zabbix3.0 + nginx 1.首先在安装好环境下安装 zabbix3.0情况下 2. yum install mysql-devel ...

  2. centos 7 && dotnet core 2.0 && nginx && supervisor

    前提 系统:centos 7 目录:/home/wwwroot/www.wuball.com dotnet core 2.0 官方指引 sudo rpm --import https://packag ...

  3. Nginx安装部署!

    安装Nginx方法一:利用u盘导入Nginx软件包 二nginx -t 用于检测配置文件语法 如下报错1:配置文件43行出现错误 [root@www ~]# nginx -tnginx: [emerg ...

  4. zabbix 3.0.3 (nginx)安装过程中的问题排错记录

    特殊注明:安装zabbix 2.4.8和2.4.6遇到2个问题,如下:找了很多解决办法,实在无解,只能换版本,尝试换(2.2.2正常 | 3.0.3正常)都正常,最后决定换3.0.3 1.Error ...

  5. nginx 安装手记 分类: Nginx 服务器搭建 2015-07-14 14:28 15人阅读 评论(0) 收藏

    Nginx需要依赖下面3个包 gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) zlib-1.2.8.tar.gz rewrite 模块需要 pcre 库 ( ...

  6. 【CNMP系列】CentOS7.0下安装Nginx服务

    话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下CentOS7.0下如何安装和配置Nginx服务 Ngi ...

  7. [Redmine] Centos5上安装Redmine3.0+nginx+thin部署

    项目管理的需要所以安装Redmine,其实wiki放在上面也不错的. 首先是安装,ruby应用第一次装,把坑记住. nginx, mysql是已经安装好的,只需要配置, 结合nginx的部署方式很多, ...

  8. 【Nginx】Nginx简介及在CentOS7.0下安装教程

    是什么 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实上nginx的并发能 ...

  9. LNMP, CentOS7.0+Nginx+Mysql5.7+PHP7环境安装

    LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.这里和家分享一下,如何在CentOS 7.0上搭建一个这样的环境,其中软件使用yum方式安装. 进入CentOS ...

随机推荐

  1. 设计模式--单例模式C++实现

    单例模式C++实现 1描述: 单例模式,又称单件模式. 定义:确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 2具体类图描述: 2.1 StartUML内部生成模式类图 该类图由S ...

  2. AsyncCallback 异步回调委托

    js是单线程语言,单线程就意味着,所有任务需要排队,前一个任务结束,才会执行后一个任务.如果前一个任务耗时很长,后一个任务就不得不一直等着. 如果排队是因为计算量大,CPU忙不过来,倒也算了,但是很多 ...

  3. C# 设计模式巩固 - 简单工厂模式

    前言 设计模式的文章很多.鄙人不才文笔也不咋地.写这篇只为巩固下基础知识,万一不小心帮到了您,是我莫大的荣幸!写的不好欢迎码友指正,废话结束开始进入正题. 介绍 - 简单工厂模式 官方定义:(尴尬~貌 ...

  4. hdu4115

    题解: 2-sat 对于bob出的每一张牌,alice显然只有两种选择 然后对于每一个限制,连边 判断是否可行 代码: #include<cstdio> #include<cmath ...

  5. LA3029

    题解: 一个类似尺取法的算法 代码: #include<cstdio> #include<algorithm> using namespace std; ; int T,n,m ...

  6. ElementTree之Xml文档处理

    ElementTree: 表示整个XML层级结构 Element: 表示树形结构中所有的父节点 SubElement: 表示树形结构中所有的子节点 有些节点既是父节点,又是子节点 下面来看下这两个类的 ...

  7. LeetCode OJ:Generate Parentheses(括号生成)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  8. Linux 内核驱动自动创建设备节点并挂载设备

    *注:本文来自http://blog.csdn.net/lwj103862095/article/details/17470573 一.首先需要在最开始定义两个数据结构: static struct ...

  9. Spring报错:java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

    感谢:http://blog.chinaunix.net/uid-20681545-id-184633.html提供的解决方案,非常棒 ! 问题说明: 新建一个Spring项目,新建一个Bean类:H ...

  10. Linux输入输出管理

      一.系统输入输出的理解 运行一个程序时,需要从某个位置读取输入信息,然后CPU处理,最后将输出 显示在屏幕或文件中:其中,某个位置相当于输入设备,屏幕或文件为输出设备. 标准输入:stdin,默认 ...