国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Nginx > 正文

配置Nginx實(shí)現(xiàn)簡單防御cc攻擊

2024-08-30 12:29:24
字體:
供稿:網(wǎng)友

ddos攻擊:分布式拒絕服務(wù)攻擊,就是利用大量肉雞或偽造IP,發(fā)起大量的服務(wù)器請求,最后導(dǎo)致服務(wù)器癱瘓的攻擊。

cc攻擊:類似于ddos攻擊,不過它的特點(diǎn)是主要是發(fā)起大量頁面請求,所以流量不大,但是卻能導(dǎo)致頁面訪問不了。

使用Nginx的配置對cc攻擊進(jìn)行簡單防御
===================================================================

主要是通過nginx和lua來配合,達(dá)到防御的目的。

一、Nginx編譯支持lua
------------------------------

1. 下載lua-nginx-module

wget https://github.com/openresty/lua-nginx-module/archive/master.zipunzip master.zip

2. 編譯

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

二、配置

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_randomif(random == nil) thenreturn ngx.redirect("/auth?url=" .. ngx.var.request_uri)endlocal token = ngx.md5("opencdn" .. ngx.var.remote_addr .. random)if(ngx.var.cookie_token ~= token) thenreturn 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) thenngx.header["Set-Cookie"] = {"token=" .. token, "random=" .. random}return ngx.redirect(ngx.var.arg_url)end';}}

是不是很簡單呢。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 建湖县| 贡山| 枣强县| 昭觉县| 酉阳| 呼伦贝尔市| 杭州市| 南城县| 长沙县| 个旧市| 江西省| 林芝县| 永和县| 遂昌县| 镇雄县| 浦北县| 广安市| 红安县| 金华市| 霸州市| 平山县| 两当县| 隆回县| 渭南市| 宁津县| 宿迁市| 连江县| 富平县| 大姚县| 温宿县| 碌曲县| 西林县| 平南县| 滨州市| 黄山市| 巩留县| 普兰店市| 绥棱县| 游戏| 安乡县| 霸州市|