亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2018年02月20日 10:38:10   作者:kaka_jon  
本文主要介紹lua+Nginx下如何快速有效得防御CC攻擊。至于如何安裝Nginx就不詳細(xì)介紹了,閑話少說,大家請看示例

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.zip
unzip 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_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
';

}
}

是不是很簡單呢。

相關(guān)文章

  • 通過Nginx+Tomcat+Redis實(shí)現(xiàn)持久會話

    通過Nginx+Tomcat+Redis實(shí)現(xiàn)持久會話

    這篇文章主要介紹了通過Nginx+Tomcat+Redis實(shí)現(xiàn)持久會話的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-11-11
  • Windows中將Nginx添加為服務(wù)的問題

    Windows中將Nginx添加為服務(wù)的問題

    這篇文章主要介紹了Windows中將Nginx添加為服務(wù)的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • Nginx本地目錄映射實(shí)現(xiàn)代碼實(shí)例

    Nginx本地目錄映射實(shí)現(xiàn)代碼實(shí)例

    這篇文章主要介紹了Nginx本地目錄映射實(shí)現(xiàn)代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-10-10
  • nginx高可用集群的實(shí)現(xiàn)過程

    nginx高可用集群的實(shí)現(xiàn)過程

    這篇文章主要介紹了nginx高可用集群的實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • Nginx配置多個訪問路徑的實(shí)現(xiàn)

    Nginx配置多個訪問路徑的實(shí)現(xiàn)

    本文主要介紹了Nginx配置多個訪問路徑的實(shí)現(xiàn),Nginx通過配置多個service就可以實(shí)現(xiàn)多訪問路徑,具有一定的參考價值,感興趣的可以了解一下
    2023-10-10
  • nginx、Apache、IIS服務(wù)器解決 413 Request Entity Too Large問題方法匯總

    nginx、Apache、IIS服務(wù)器解決 413 Request Entity Too Large問題方法匯總

    這篇文章主要介紹了nginx、Apache、IIS三種服務(wù)器解決413 Request Entity Too Large問題的方法集合,需要的朋友可以參考下
    2014-05-05
  • nginx日志分割 for linux

    nginx日志分割 for linux

    默認(rèn)情況下,nginx是不分割訪問日志的,久而久之,網(wǎng)站的日志文件將會越來越大,占用空間不說,如果有問題要查看網(wǎng)站的日志的話,龐大的文件也將很難打開,于是便有了下面的腳本
    2013-11-11
  • Tomcat請求處理在源碼中的輪轉(zhuǎn)解析

    Tomcat請求處理在源碼中的輪轉(zhuǎn)解析

    這篇文章主要為大家介紹了Tomcat請求處理在源碼中的輪轉(zhuǎn)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • Nginx搭建負(fù)載均衡集群的實(shí)現(xiàn)

    Nginx搭建負(fù)載均衡集群的實(shí)現(xiàn)

    這篇文章主要介紹了Nginx搭建負(fù)載均衡集群的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • linux上nginx安裝部署及使用過程詳解

    linux上nginx安裝部署及使用過程詳解

    這篇文章主要介紹了linux上nginx安裝部署及使用過程,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2019-11-11

最新評論