• 本帖最后由 lazyzhu 于 2013-5-4 19:23 编辑 *

由我blog文章改编而来
http://lazyzhu.com/Nginx/LNMP-compile-nginx-redis-module-to-build-redis-cache.html
这是最简单最没技术含量的,只要简单加两行配置就行

其实可以还有更强大的功能:
将CC攻击的IP自动添加进机房路由器防火墙(有条件的话)
将CC攻击的IP自动添加进iptables防火墙
将CC攻击的IP封禁自定义时间,过后自动释放
将被CC攻击的页面进行缓存,降低后端资源
将CC攻击的IP转向自定义网页,或随机网页
......

  1. 停止LNMP服务

"

  1. 备份LNMP配置

"

3.重编译nginx + limit_req2_nginx_module

"
"
"

  1. 修改Nginx配置

**log_format lazyzhu.com '$remote_addr - $remote_user [$time_local] $request '
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';

limit_req2_zone $request_uri zone=lazyzhu.com.one:2m rate=5r/s;
limit_req2_zone $binary_remote_addr zone=lazyzhu.com.two:2m rate=30r/s;

server {
listen 80;
server_name lazyzhu.com;
root /home/wwwroot/lazyzhu.com;
location / {
index index.html index.htm index.php default.html default.htm default.php;
}
include none.conf;
## folder disable limit
location ^~ /(wp-admin|admin)/ {
limit_req2 off;
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
## file disable limit
location ~ .*(admin|p)\.(php|php5)?$ {
limit_req2 off;
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(php|php5)?$ {

limit_req2 zone=lazyzhu.com.one forbid_action=@444 nodelay;

limit_req2 zone=lazyzhu.com.two forbid_action=@444 nodelay;

try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location @444 {
return 444;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location /status {
stub_status on;
access_log off;
}
access_log /home/wwwlogs/lazyzhu.com.log lazyzhu.com;
}**

  1. 启动LNMP服务

"