小知识:配置Nginx实现简单防御cc攻击

ddos攻击:分布式拒绝服务攻击,就是利用大量肉鸡或伪造IP,发起大量的服务器请求,最后导致服务器瘫痪的攻击。

cc攻击:类似于ddos攻击,不过它的特点是主要是发起大量页面请求,所以流量不大,但是却能导致页面访问不了。

使用Nginx的配置对cc攻击进行简单防御

===================================================================

主要是通过nginx和lua来配合,达到防御的目的。

一、Nginx编译支持lua

——————————

1. 下载lua-nginx-module

?
1
2
wget https://github.com/openresty/lua-nginx-module/archive/master.zip
unzip master.zip

2. 编译

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#./configure \
–user=nginx \
–group=nginx \
–prefix=/usr/local/gacp/nginx \
–error-log-path=/data/logs/nginx/error/error.log \
–http-log-path=/data/logs/nginx/access/access.log \
–pid-path=/usr/local/gacp/nginx/conf/nginx.pid \
–lock-path=/var/lock/nginx.lock \
–with-http_flv_module \
–with-http_stub_status_module \
–with-http_ssl_module \
–with-pcre \
–with-http_realip_module \
–with-http_gzip_static_module \
–with-google_perftools_module \
–with-file-aio \
–add-module=../ngx_cache_purge-2.3 \
–add-module=../lua-nginx-module-master
# make && make install

二、配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
http {
…..
limit_req_zone $cookie_token zone=session_limit:3m rate=1r/s;
limit_req_zone $binary_remote_addr $uri zone=auth_limit:3m rate=1r/m;
}
server {
listen 80;
server_name localhost;
access_log /data/logs/nginx/access/localhost.access.log main;
error_log /data/logs/nginx/error/localhost.error.log;
charset utf-8;
client_max_body_size 75M;
root /data/www;
location / {
limit_req zone=session_limit burst=5;
rewrite_by_lua
local random = ngx.var.cookie_random
if(random == nil) then
return ngx.redirect(“/auth?url=” .. ngx.var.request_uri)
end
local token = ngx.md5(“opencdn” .. ngx.var.remote_addr .. random)
if(ngx.var.cookie_token ~= token) then
return ngx.redirect(“/auth?url=” .. ngx.var.request_uri)
end
;
}
location /auth {
limit_req zone=auth_limit burst=1;
if ($arg_url = “”) {
return 403;
}
access_by_lua
local random = math.random(9999)
local token = ngx.md5(“opencdn” .. ngx.var.remote_addr .. random)
if(ngx.var.cookie_token ~= token) then
ngx.header[“Set-Cookie”] = {“token=” .. token, “random=” .. random}
return ngx.redirect(ngx.var.arg_url)
end
;
}
}

是不是很简单呢。

原文链接:https://www.cnblogs.com/zhaojonjon/p/8454845.html

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:LINUX重启MYSQL的命令详解

2023-4-20 2:45:13

建站知识

小知识:详解Linux添加/删除用户和用户组

2023-4-20 2:53:24

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索