如何配置Nginx防御cc攻击

时间:2022-12-06 03:33

配置Nginx防御cc攻击的方法:1、下载lua,并使用Nginx进行编译;2、编译完成后,对相关文件进行修改配置,即可完成配置防御cc攻击。

如何配置Nginx防御cc攻击

具体内容如下:

1、Nginx编译支持lua

下载lua-nginx-module

编译

#./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&&makeinstall

2、配置

http{

.....

limit_req_zone$cookie_tokenzone=session_limit:3mrate=1r/s;

limit_req_zone$binary_remote_addr$urizone=auth_limit:3mrate=1r/m;

}

server{

listen80;

server_namelocalhost;

access_log/data/logs/nginx/access/localhost.access.logmain;

error_log/data/logs/nginx/error/localhost.error.log;

charsetutf-8;

client_max_body_size75M;

root/data/www;

location/{

limit_reqzone=session_limitburst=5;

rewrite_by_lua'

localrandom=ngx.var.cookie_random

if(random==nil)then

returnngx.redirect("/auth?url="..ngx.var.request_uri)

end

localtoken=ngx.md5("opencdn"..ngx.var.remote_addr..random)

if(ngx.var.cookie_token~=token)then

returnngx.redirect("/auth?url="..ngx.var.request_uri)

end

';

}

location/auth{

limit_reqzone=auth_limitburst=1;

if($arg_url=""){

return403;

}

access_by_lua'

localrandom=math.random(9999)

localtoken=ngx.md5("opencdn"..ngx.var.remote_addr..random)

if(ngx.var.cookie_token~=token)then

ngx.header["Set-Cookie"]={"token="..token,"random="..random}

returnngx.redirect(ngx.var.arg_url)

end

';

}

}

标签:
随便看看
本类推荐
本类排行
热门标签

我国国家通讯社行不行啊细狗新年贺词祝福语2023年祝福语新年新年贺词新年贺词祝福语居家抗病毒小药箱除夕高速免费吗2022年除夕高速免费吗春联春联句子大全春联句子大全七字年夜饭十二道菜年夜饭十二道菜单年夜饭吃什么年夜饭吃什么菜吃年夜饭的寓意年夜饭黑芝麻菊花茶晒菊花茶腌腊肉送妈妈生日礼物汉白玉送闺蜜水钻送女人礼物爸爸生日送礼物送老公