Linux服务器故障排查基本方案( 二 )

catwww.XXX.com-access.log | awk '{print $10}' | sort | uniq -c | sort -nr | head -n 10执行时间最长10条catwww.XXX.com-access.log | sort -nr | head -n 10查看http_referer来路:cat www.XXX.com-access.log | awk -F"from:" '{print $NF}' |sort|uniq -c|sort -nr|head -10封IP,查看特定的referer来源地址
服务器防火墙封ip封IP段
/sbin/iptables -I INPUT -s 61.37.80.0/24 -j DROP#屏蔽单个IP的命令是 deny 123.45.6.7 #封整个段即从123.0.0.1到123.255.255.254的命令 deny 123.0.0.0/8禁止特定用户代理(User Agents)访问if ($http_user_agent ~* (wget|curl|Firefox) ) {return 404;}特定的地址攻击做跳转rewrite ^/accounts/+$str+ http://127.0.0.1/ redirect;根据 user_agent 控制客户端访问location / {if ($http_user_agent ~ 'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315'){return 403;}}图片防盗链valid_referers none blocked *.XXX.com server_names ~.google. ~.baidu.;if ($invalid_referer) {# return 403;rewrite ^/ http://www.XXX.com/daoling.png;} 
不允许host为localhost访问if ($host = 'localhost') {return 403;}不允许agent为空if ($http_user_agent ~ ^$){return 403;}不允许绑定host主机访问if ($http_x_forwarded_for ~ ^$){return 402;}



推荐阅读