如何配置Nginx防御cc攻击(nginx 防cc配置)

如何配置Nginx防御cc攻击(nginx 防cc配置)

扫码添加渲大师小管家,免费领取渲染插件、素材、模型、教程合集大礼包!

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

如何配置Nginx防御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

';

}

}

分享到 :
相关推荐

香港原生ip服务器是什么(香港原生ip服务器是什么意思)

香港原生IP服务器是指服务器提供商提供的具有香港独立IP地址的服务器。而不是共享IP...

多ip香港vps怎么选择(香港多ip vps)

多ip香港vps选择的方法:1。普通网站选择2核左右的CPU。流量大的网站选择4核及...

FileZilla Server搭建FTP服务器配置及425错误与TLS警告解决方法详解(ftp服务器425报错)

渲大师为大家提供FileZilla下载链接:FileZillaServer服务端[&...

台湾vps主机租用有哪些优势

台湾vps主机租用的优势有:1。IP资源独立。能避免网站受他人因素影响。有效提高了网...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注