modsecurity3.0 nginx 安装
备注:
使用的是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
load_module modules/ngx_http_modsecurity_module.so;
备注: 位置 nginx main
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;
}
}
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;
sbin/nginx -t
备注: 如果不报错说明没有问题,报错可以参考日志解决
实际上,上面的配置是如果请求参考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
同时支持 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
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 安装的更多相关文章
- 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 ...
- centos 7 && dotnet core 2.0 && nginx && supervisor
前提 系统:centos 7 目录:/home/wwwroot/www.wuball.com dotnet core 2.0 官方指引 sudo rpm --import https://packag ...
- Nginx安装部署!
安装Nginx方法一:利用u盘导入Nginx软件包 二nginx -t 用于检测配置文件语法 如下报错1:配置文件43行出现错误 [root@www ~]# nginx -tnginx: [emerg ...
- zabbix 3.0.3 (nginx)安装过程中的问题排错记录
特殊注明:安装zabbix 2.4.8和2.4.6遇到2个问题,如下:找了很多解决办法,实在无解,只能换版本,尝试换(2.2.2正常 | 3.0.3正常)都正常,最后决定换3.0.3 1.Error ...
- 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 库 ( ...
- 【CNMP系列】CentOS7.0下安装Nginx服务
话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下CentOS7.0下如何安装和配置Nginx服务 Ngi ...
- [Redmine] Centos5上安装Redmine3.0+nginx+thin部署
项目管理的需要所以安装Redmine,其实wiki放在上面也不错的. 首先是安装,ruby应用第一次装,把坑记住. nginx, mysql是已经安装好的,只需要配置, 结合nginx的部署方式很多, ...
- 【Nginx】Nginx简介及在CentOS7.0下安装教程
是什么 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实上nginx的并发能 ...
- LNMP, CentOS7.0+Nginx+Mysql5.7+PHP7环境安装
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构.这里和家分享一下,如何在CentOS 7.0上搭建一个这样的环境,其中软件使用yum方式安装. 进入CentOS ...
随机推荐
- spring mvc:练习 @RequestParam(参数绑定到控制器)和@PathVariable(参数绑定到url模板变量)
spring mvc:练习 @RequestParam和@PathVariable @RequestParam: 注解将请求参数绑定到你的控制器方法参数 @PathVariable: 注释将一个方法参 ...
- LR--实现HTTP协议的接口测试
场景分析:使用LR完成HTTP协议的接口测试 流程: 1.首先需要找一个接口(POST.GET接口) 2.LR中点击Insert-->New Step-->web_custom_reque ...
- Elasticsearch知识整理
1:es介绍 Elasticsearch是一个基于Lucene的实时的分布式搜索和分析引擎.设计用于云计算中, 能够达到实时搜索,稳定,可靠,快速,安装使用方便.基 ...
- mongodb安装与权限配置
mongodb下载地址:官方下载IDE工具:Robo 3T:官方下载 windows系统要求64位,最低2g内存,推荐8g内存及以上 安装过程没有需要配置的地方,直接下一步到结束,如果想要方便可以在环 ...
- 原生javascript-无间缝滚动,封装
目前支持的是竖向与横向滚动 http://lgy.1zwq.com/marScroll/ 现在分析下无间缝实现的基本思路(竖向例子): HTML结构: <div id="marScro ...
- 【小米oj】找出单独的数字
题目链接:https://code.mi.com/problem/list/view?id=2&cid=0&sid=26251#codearea 描述 给出N个数字.其中仅有一个数字出 ...
- Spring Framework Artifacts
GroupId ArtifactId Description org.springframework spring-aop Proxy-based AOP support org.springfram ...
- Github上的iOS App源码 (中文)
Github版英文App地址 中文 : TeamTalk 蘑菇街. 开源IM. 电商强烈推荐. MyOne-iOS 用OC写的<一个> iOS 客户端 zhihuDaily 高仿知乎日报 ...
- Java语言基础-运算符
一丶逻辑运算符 1.&和&&的区别 (1).两个逻辑运算符的结果是一样的 (2).当第一个表达式为false时,&是会判断后边的表达式,而&&会产生短路 ...
- New Concept English three(13)
1原文打字 32w/m 错词27个 After her husband had gone to work, Mrs Richards sent her children to school and w ...