nginx ÊǸö²»´íµÄweb·þÎñÆ÷£¬ÌṩÁËÈ«·½Î»µÄÏÞËÙ¹¦ÄÜ£¬Ö÷ÒªµÄ¹¦ÄÜÄ£¿éÊÇngx_http_core_module¡¢ ngx_http_limit_conn_moduleºÍ ngx_http_limit_req_module£¬µÚÒ»¸öÄ£¿éÖÐÓÐlimit_rate¹¦ÄÜ£¨ÏÞÍøËÙ´ø¿í£©£¬ºóÁ½¸öÄ£¿é´Ó×ÖÃæÉϽ²£¬¹¦ÄÜ·Ö±ðÊÇÏÞÖÆÁ¬ ½Ó£¨limit connection£©ºÍÏÞÖÆÇëÇó£¨limit request£©£¬Õ⼸¸öÄ£¿éĬÈ϶¼±àÒë½øÁËnginxºËÐÄ¡£
ËùÓеÄÏÞÖƶ¼ÊÇÕë¶ÔIPµÄ£¬Òò´Ë¶ÔCC¡¢DDOSÓÐÒ»¶¨µÄ·ÀÓù×÷Óá£
ÏÞ´ø¿íºÜÈÝÒ×Ã÷°×£¬Ö±½ÓÉÏÀý×Ó
location /mp3 { limit_rate 200k; }
ÓÐÒ»ÖÖ·½Ê½¿ÉÒÔÈÃÏÞËÙ¸ü¼ÓÈËÐÔ»¯£¬¼´´«ÊäÒ»¶¨Á÷Á¿ºó¿ªÊ¼ÏÞËÙ,
±ÈÈçÏÈÈ«ËÙ´«Êä1M£¬È»ºó¿ªÊ¼ÏÞËÙ£º
location /photo { limit_rate_after 1m; limit_rate 100k; }
½ÓÏÂÀ´½²ÏÞ²¢·¢ÊýºÍÇëÇóÊý¡£
ΪʲôÓÐÕâÁ½¸öÄ£¿éÄØ£¿ÒòΪÎÒÃÇÖªµÀ£¬Ò»¸öÒ³Ãæͨ³£Óжà¸ö×ÓÄ£¿é£¬Æ©Èç5ÕÅͼƬ£¬ÄÇôÎÒÃÇÇëÇóÕâ¸öÒ³Ãæʱ·¢ÆðÁËÒ»¸öÁ¬½Ó£¬µ«ÊÇÕâÒ»¸öÁ¬½Ó°üº¬ÁË5´ÎͼƬÇëÇó£¬Ò²¾ÍÊÇ˵£¬Ò»¸öÁ¬½Ó¿ÉÒÔ·¢Æð¶à´ÎÇëÇó¡£ÎÒÃÇΪÁËά³ÖÓû§ÌåÑ飬ÊÇÏÞÖÆÁ¬½ÓÊý»¹ÊÇÇëÇóÊý£¬Òª¸ù¾Ýʵ¼ÊÐèÒª½øÐÐÑ¡Ôñ¡£
1¡¢ÏÞÖÆÁ¬½ÓÊý
ÒªÏÞÖÆÁ¬½Ó£¬±ØÐëÏÈÓÐÒ»¸öÈÝÆ÷¶ÔÁ¬½Ó½øÐмÆÊý£¬ÔÚhttp¶Î¼ÓÈëÈçÏ´úÂ룺
limit_conn_zone $binary_remote_addr zone=addr:5m;
ÕâÑù¾ÍÔÚÄÚ´æÖд´½¨ÁËÒ»¸ö5M´óС£¬ÃûΪaddrµÄÏÞËٳأ¨Ã¿¸öÁ¬½ÓÕ¼ÓÃ32»ò64×Ö½Ú£¬5m´óС¿ÉÈÝÄÉÊýÒÔÍò¼ÆµÄÁ¬½Ó£¬Í¨³£ÊÇ×ã¹»µÄ£¬Èç¹û5MÄÚ´æºÄ¾¡£¬½«·µ»Ø503£©
½ÓÏÂÀ´ÐèÒª¶Ôserver²»Í¬µÄλÖã¨location¶Î£©½øÐÐÏÞËÙ£¬±ÈÈçÏÞÖÆÿ¸öIP²¢·¢Á¬½ÓÊýΪ2£¬Ôò
limit_conn addr 2;
2¡¢ÏÞÖÆÇëÇóÊý
ÒªÏÞÖÆÇëÇóÊý£¬Ò²±ØÐëÏÈ´´½¨Ò»¸öÏÞËٳأ¬ÔÚhttp¶Î¼ÓÈëÈçÏ´úÂ룺
limit_req_zone $binary_remote_addr zone=one:5m;
ÏÞËÙ·ÖΪȫ¾ÖÏÞËٺ;ֲ¿ÏÞËÙ£¬
¶ÔÓÚÈ«¾ÖÏÞËÙ£¬ÎÒÃÇÖ»ÐèÒªÔÚºóÃæ¼ÓÉϲÎÊý¼´¿É£¬±ÈÈçÿÃë20¸öÇëÇó£¬rate=20r/s£¬¼´:
limit_req_zone $binary_remote_addr zone=perip:5m rate=20r/s;
ÓÐʱºòÎÒÃÇÏ£ÍûÔÚlocation¶Îµ÷ÕûÒ»ÏÂÁ´½Ó£¬¿ÉÒÔ½èÖúburst²ÎÊý
limit_req zone=one burst=50;
Èç¹û²»Ï£ÍûÑÓʱ£¬»¹ÓÐnodelay²ÎÊý
limit_req zone=one burst=50 nodelay;
ÒÔÉÏÊÇnginxµÄÏÞËÙ¹¦Äܼò½é£¬²»µ±Ö®´¦£¬»¶ÓÖ¸Õý¡£ÖÁÓÚ¾ßÌåʹÓÃÄÄÖÖÏÞËÙ·½·¨£¬Ò»¶¨ÒªÕå×ã¬ÒÔÃâÆÆ»µÓû§ÌåÑé¡£
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ