{"id":139194,"date":"2019-03-17T08:31:25","date_gmt":"2019-03-17T00:31:25","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=139194"},"modified":"2019-03-08T09:32:39","modified_gmt":"2019-03-08T01:32:39","slug":"nginx-limit-module","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nginx-limit-module.html","title":{"rendered":"\u4ecb\u7ecdnginx_http_limit\u6a21\u5757\u8be6\u7ec6\u8bed\u6cd5\u53ca\u4f7f\u7528"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u901a\u8fc7ngx_http_limit_req_module \u6a21\u5757\u6765\u5b9e\u73b0\uff0c\u8be5\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u7684 \u952e\u503c\u6765\u9650\u5236\u8bf7\u6c42\u5904\u7406\u7684\u9891\u7387\u3002\u7279\u522b\u7684\uff0c\u53ef\u4ee5\u9650\u5236\u6765\u81ea\u5355\u4e2aIP\u5730\u5740\u7684\u8bf7\u6c42\u5904\u7406\u9891\u7387\u3002 \u9650\u5236\u7684\u65b9\u6cd5\u5982\u540c\u6f0f\u6597\uff0c\u6bcf\u79d2\u56fa\u5b9a\u5904\u7406\u8bf7\u6c42\u6570\uff0c\u63a8\u8fdf\u8fc7\u591a\u8bf7\u6c42\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
limit_req_zone<\/strong><\/span><\/div>\n
\r\n\u8bed\u6cd5: limit_req_zone $variable zone=name:size rate=rate;\r\n\u9ed8\u8ba4\u503c: none\r\n\u914d\u7f6e\u6bb5: http\r\n<\/pre>\n

\u8bbe\u7f6e\u4e00\u5757\u5171\u4eab\u5185\u5b58\u9650\u5236\u57df\u7528\u6765\u4fdd\u5b58\u952e\u503c\u7684\u72b6\u6001\u53c2\u6570\u3002 \u7279\u522b\u662f\u4fdd\u5b58\u4e86\u5f53\u524d\u8d85\u51fa\u8bf7\u6c42\u7684\u6570\u91cf\u3002 \u952e\u7684\u503c\u5c31\u662f\u6307\u5b9a\u7684\u53d8\u91cf\uff08\u7a7a\u503c\u4e0d\u4f1a\u88ab\u8ba1\u7b97\uff09\u3002\u5982<\/p>\n

limit_req_zone $binary_remote_addr zone=one:10m rate=1r\/s;<\/strong><\/span><\/div>\n
\r\n\u8bf4\u660e\uff1a\u533a\u57df\u540d\u79f0\u4e3aone\uff0c\u5927\u5c0f\u4e3a10m\uff0c\u5e73\u5747\u5904\u7406\u7684\u8bf7\u6c42\u9891\u7387\u4e0d\u80fd\u8d85\u8fc7\u6bcf\u79d2\u4e00\u6b21\u3002\r\n\u952e\u503c\u662f\u5ba2\u6237\u7aefIP\u3002\r\n\u4f7f\u7528$binary_remote_addr\u53d8\u91cf\uff0c \u53ef\u4ee5\u5c06\u6bcf\u6761\u72b6\u6001\u8bb0\u5f55\u7684\u5927\u5c0f\u51cf\u5c11\u523064\u4e2a\u5b57\u8282\uff0c\u8fd9\u68371M\u7684\u5185\u5b58\u53ef\u4ee5\u4fdd\u5b58\u5927\u7ea61\u4e076\u5343\u4e2a64\u5b57\u8282\u7684\u8bb0\u5f55\u3002\r\n\u5982\u679c\u9650\u5236\u57df\u7684\u5b58\u50a8\u7a7a\u95f4\u8017\u5c3d\u4e86\uff0c\u5bf9\u4e8e\u540e\u7eed\u6240\u6709\u8bf7\u6c42\uff0c\u670d\u52a1\u5668\u90fd\u4f1a\u8fd4\u56de 503 (Service Temporarily Unavailable)\u9519\u8bef\u3002\r\n<\/pre>\n

\u901f\u5ea6\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u6bcf\u79d2\u5904\u7406\u8bf7\u6c42\u6570\u548c\u6bcf\u5206\u949f\u5904\u7406\u8bf7\u6c42\u6570\uff0c\u5176\u503c\u5fc5\u987b\u662f\u6574\u6570\uff0c\u6240\u4ee5\u5982\u679c\u4f60\u9700\u8981\u6307\u5b9a\u6bcf\u79d2\u5904\u7406\u5c11\u4e8e1\u4e2a\u7684\u8bf7\u6c42\uff0c2\u79d2\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\uff0c\u53ef\u4ee5\u4f7f\u7528 \u201c30r\/m\u201d\u3002<\/p>\n

limit_req_log_level<\/strong><\/span><\/div>\n
\r\n\u8bed\u6cd5: limit_req_log_level info | notice | warn | error;\r\n\u9ed8\u8ba4\u503c: limit_req_log_level error;\r\n\u914d\u7f6e\u6bb5: http, server, location\r\n<\/pre>\n

\u8bbe\u7f6e\u4f60\u6240\u5e0c\u671b\u7684\u65e5\u5fd7\u7ea7\u522b\uff0c\u5f53\u670d\u52a1\u5668\u56e0\u4e3a\u9891\u7387\u8fc7\u9ad8\u62d2\u7edd\u6216\u8005\u5ef6\u8fdf\u5904\u7406\u8bf7\u6c42\u65f6\u53ef\u4ee5\u8bb0\u4e0b\u76f8\u5e94\u7ea7\u522b\u7684\u65e5\u5fd7\u3002 \u5ef6\u8fdf\u8bb0\u5f55\u7684\u65e5\u5fd7\u7ea7\u522b\u6bd4\u62d2\u7edd\u7684\u4f4e\u4e00\u4e2a\u7ea7\u522b\uff1b\u6bd4\u5982\uff0c \u5982\u679c\u8bbe\u7f6e\u201climit_req_log_level notice\u201d\uff0c \u5ef6\u8fdf\u7684\u65e5\u5fd7\u5c31\u662finfo\u7ea7\u522b\u3002<\/p>\n

limit_req_status<\/strong><\/span><\/div>\n
\r\n\u8bed\u6cd5: limit_req_status code;\r\n\u9ed8\u8ba4\u503c: limit_req_status 503;\r\n\u914d\u7f6e\u6bb5: http, server, location\r\n<\/pre>\n

\u8be5\u6307\u4ee4\u57281.3.15\u7248\u672c\u5f15\u5165\u3002\u8bbe\u7f6e\u62d2\u7edd\u8bf7\u6c42\u7684\u54cd\u5e94\u72b6\u6001\u7801\u3002<\/p>\n

limit_req<\/strong><\/span><\/div>\n
\r\n\u8bed\u6cd5: limit_req zone=name [burst=number] [nodelay];\r\n\u9ed8\u8ba4\u503c: \u2014\r\n\u914d\u7f6e\u6bb5: http, server, location\r\n<\/pre>\n

\u8bbe\u7f6e\u5bf9\u5e94\u7684\u5171\u4eab\u5185\u5b58\u9650\u5236\u57df\u548c\u5141\u8bb8\u88ab\u5904\u7406\u7684\u6700\u5927\u8bf7\u6c42\u6570\u9608\u503c\u3002 \u5982\u679c\u8bf7\u6c42\u7684\u9891\u7387\u8d85\u8fc7\u4e86\u9650\u5236\u57df\u914d\u7f6e\u7684\u503c\uff0c\u8bf7\u6c42\u5904\u7406\u4f1a\u88ab\u5ef6\u8fdf\uff0c\u6240\u4ee5\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u662f\u4ee5\u5b9a\u4e49\u7684\u9891\u7387\u88ab\u5904\u7406\u7684\u3002 \u8d85\u8fc7\u9891\u7387\u9650\u5236\u7684\u8bf7\u6c42\u4f1a\u88ab\u5ef6\u8fdf\uff0c\u76f4\u5230\u88ab\u5ef6\u8fdf\u7684\u8bf7\u6c42\u6570\u8d85\u8fc7\u4e86\u5b9a\u4e49\u7684\u9608\u503c\uff0c\u8fd9\u65f6\uff0c\u8fd9\u4e2a\u8bf7\u6c42\u4f1a\u88ab\u7ec8\u6b62\uff0c\u5e76\u8fd4\u56de503 (Service Temporarily Unavailable) \u9519\u8bef\u3002\u8fd9\u4e2a\u9608\u503c\u7684\u9ed8\u8ba4\u503c\u4e3a0\u3002\u5982\uff1a<\/p>\n

\r\nlimit_req_zone $binary_remote_addr zone=ttlsa_com:10m rate=1r\/s;\r\nserver {\r\n    location \/www.ttlsa.com\/ {\r\n        limit_req zone=ttlsa_com burst=5;\r\n    }\r\n}\r\n<\/pre>\n

\u9650\u5236\u5e73\u5747\u6bcf\u79d2\u4e0d\u8d85\u8fc7\u4e00\u4e2a\u8bf7\u6c42\uff0c\u540c\u65f6\u5141\u8bb8\u8d85\u8fc7\u9891\u7387\u9650\u5236\u7684\u8bf7\u6c42\u6570\u4e0d\u591a\u4e8e5\u4e2a\u3002<\/p>\n

\u5982\u679c\u4e0d\u5e0c\u671b\u8d85\u8fc7\u7684\u8bf7\u6c42\u88ab\u5ef6\u8fdf\uff0c\u53ef\u4ee5\u7528nodelay\u53c2\u6570,\u5982\uff1a<\/p>\n

limit_req zone=ttlsa_com burst=5 nodelay;<\/strong><\/span><\/div>\n

\u5b8c\u6574\u5b9e\u4f8b\u914d\u7f6e<\/p>\n

\r\nhttp {\r\n    limit_req_zone $binary_remote_addr zone=ttlsa_com:10m rate=1r\/s;\r\n\r\n    server {\r\n        location  ^~ \/download\/ {  \r\n        limit_req zone=ttlsa_com burst=5;\r\n        alias \/data\/www.ttlsa.com\/download\/;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n

\u53ef\u80fd\u8981\u5bf9\u67d0\u4e9bIP\u4e0d\u505a\u9650\u5236\uff0c\u9700\u8981\u4f7f\u7528\u5230\u767d\u540d\u5355\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8bed\u6cd5: limit_req_zone $variable zone=name:size rate=rate; […]<\/p>\n","protected":false},"author":668,"featured_media":7920,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-139194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=139194"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139194\/revisions"}],"predecessor-version":[{"id":139271,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139194\/revisions\/139271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/7920"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=139194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=139194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=139194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}