{"id":9573,"date":"2024-04-01T16:41:30","date_gmt":"2024-04-01T08:41:30","guid":{"rendered":"https:\/\/egonlin.com\/?p=9573"},"modified":"2024-06-03T19:45:56","modified_gmt":"2024-06-03T11:45:56","slug":"9573","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=9573","title":{"rendered":"nginx\u4e00\u4e9b\u5e38\u7528\u6a21\u5757"},"content":{"rendered":"<h2>nginx\u4e00\u4e9b\u5e38\u7528\u6a21\u5757<\/h2>\n<p>\u6a21\u5757\u5f88\u591a\uff0c\u5b66\u4e0d\u5b8c\u7684\uff0c\u7785\u4e00\u773c\uff0c\u6709\u4e2a\u57fa\u672c\u5370\u8c61\u5373\u53ef<\/p>\n<h3>1.\u76ee\u5f55\u7d22\u5f15\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\"># ngx_http_autoindex_module\r\n\r\nngx_http_autoindex_module\u6a21\u5757\u5904\u7406\u4ee5\u659c\u6760\u5b57\u7b26\uff08'\/'\uff09\u7ed3\u5c3e\u7684\u8bf7\u6c42\uff0c\u5e76\u751f\u6210\u76ee\u5f55\u5217\u8868\u3002\r\n\r\n\u5f53ngx_http_index_module\u6a21\u5757\u627e\u4e0d\u5230\u7d22\u5f15\u6587\u4ef6\u65f6\uff0c\u901a\u5e38\u4f1a\u5c06\u8bf7\u6c42\u4f20\u9012\u7ed9ngx_http_autoindex_module\u6a21\u5757\u3002<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">Syntax: autoindex on | off;\r\nDefault:    autoindex off;\r\nContext:    http, server, location<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n    }\r\n}<\/code><\/pre>\n<h4>3\uff09\u8bbf\u95ee\u7f51\u7ad9\u6b63\u5e38\uff0c\u52a0download\u8df3\u8f6c\u76ee\u5f55\u9875\u9762<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n    }\r\n}\r\n\r\n#\u521b\u5efa\u7ad9\u70b9\u76ee\u5f55\r\n[root@web01 ~]# mkdir \/code\/autoindex\/download -p\r\n[root@web01 ~]# echo \"\u6d4b\u8bd5autoindex\u6a21\u5757\" &gt; \/code\/autoindex\/index.html\r\n\r\n#\u8bbf\u95ee\r\nhttp:\/\/www.autoindex.com\/       \u4e3a\u4e3b\u7ad9\r\nhttp:\/\/www.autoindex.com\/download\/      \u4e3a\u4e0b\u8f7d\u6587\u4ef6\u7684\u76ee\u5f55<\/code><\/pre>\n<h4>4\uff09\u5e38\u7528\u4f18\u5316\u53c2\u6570<\/h4>\n<pre><code class=\"language-bash\">#\u663e\u793a\u6587\u4ef6\u5b57\u8282\u5927\u5c0f\uff0c\u9ed8\u8ba4\u662f\u663e\u793a\u5b57\u8282\u5927\u5c0f\uff0c\u914d\u7f6e\u4e3aoff\u4e4b\u540e\uff0c\u663e\u793a\u5177\u4f53\u5927\u5c0f M\/G\/K\r\nSyntax: autoindex_exact_size on | off;\r\nDefault:    autoindex_exact_size on;\r\nContext:    http, server, location\r\n\r\n#\u663e\u793a\u6587\u4ef6\u7684\u4fee\u6539\u7684\u5177\u4f53\u65f6\u95f4\uff0c\u9ed8\u8ba4\u663e\u793a\u7684\u65f6\u95f4\u4e0e\u771f\u5b9e\u65f6\u95f4\u76f8\u5dee8\u5c0f\u65f6\uff0c\u6240\u4ee5\u914d\u7f6e on\r\nSyntax: autoindex_localtime on | off;\r\nDefault:    autoindex_localtime off;\r\nContext:    http, server, location<\/code><\/pre>\n<h4>5\uff09\u5b8c\u6574\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# cat \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n    root \/code\/autoindex;\r\n    index index.html;\r\n    }\r\n\r\n    location \/download {\r\n    root \/code\/autoindex;\r\n    autoindex on;\r\n    autoindex_exact_size off;\r\n    autoindex_localtime on;\r\n    }\r\n}<\/code><\/pre>\n<h3>2.Nginx\u8bbf\u95ee\u63a7\u5236\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\">#ngx_http_access_module<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u5141\u8bb8\u8bbf\u95ee\u7684\u8bed\u6cd5\r\nSyntax: allow address | all;\r\nDefault:    \u2014\r\nContext:    http, server, location, limit_except\r\n\r\n#\u62d2\u7edd\u8bbf\u95ee\u7684\u8bed\u6cd5\r\nSyntax: deny address | all;\r\nDefault:    \u2014\r\nContext:    http, server, location, limit_except\r\n\r\n#\u5982\u679c\u914d\u7f6e\u5141\u8bb8\uff0c\u5219\u4e5f\u8981\u914d\u7f6e\u62d2\u7edd\uff1b\u914d\u7f6e\u62d2\u7edd\u53ef\u4ee5\u5355\u72ec\u914d\u7f6e<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e\u8bbf\u95ee\u63a7\u5236\u793a\u4f8b<\/h4>\n<h5>1&gt;\u62d2\u7edd\u6307\u5b9a\u7684IP,\u5176\u4ed6\u5168\u90e8\u5141\u8bb8<\/h5>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n        autoindex_exact_size off;\r\n        autoindex_localtime on;\r\n        deny 10.0.0.1;\r\n        allow all;\r\n    }\r\n}<\/code><\/pre>\n<h5>2&gt;\u53ea\u5141\u8bb8\u6307\u5b9aIP\u80fd\u8bbf\u95ee, \u5176\u5b83\u5168\u90e8\u62d2\u7edd<\/h5>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n        autoindex_exact_size off;\r\n        autoindex_localtime on;\r\n        allow 10.0.0.1;\r\n        #\u5982\u679c\u4f7f\u7528all\uff0c\u4e00\u5b9a\u653e\u5728\u6700\u540e\u9762\r\n        deny all;\r\n    }\r\n}<\/code><\/pre>\n<h5>3&gt;\u53ea\u5141\u8bb810.0.0.1\u8bbf\u95ee\uff0c\u62d2\u7edd\u8be5\u7f51\u6bb5\u5176\u4ed6IP<\/h5>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n        autoindex_exact_size off;\r\n        autoindex_localtime on;\r\n        allow 10.0.0.1;\r\n        #\u5982\u679c\u4f7f\u7528all\uff0c\u4e00\u5b9a\u653e\u5728\u6700\u540e\u9762\r\n        deny 10.0.0.0\/24;\r\n    }\r\n}<\/code><\/pre>\n<h3>3.Nginx\u8bbf\u95ee\u8ba4\u8bc1\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\"># ngx_http_auth_basic_module<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u5f00\u542f\u7684\u767b\u5f55\u8ba4\u8bc1\uff0c\u6ca1\u6709\u5375\u7528\r\nSyntax: auth_basic string | off;\r\nDefault:    auth_basic off;\r\nContext:    http, server, location, limit_except\r\n\r\n#\u6307\u5b9a\u767b\u5f55\u7528\u7684\u7528\u6237\u540d\u5bc6\u7801\u6587\u4ef6\r\nSyntax: auth_basic_user_file file;\r\nDefault:    \u2014\r\nContext:    http, server, location, limit_except<\/code><\/pre>\n<h4>2\uff09\u521b\u5efa\u5bc6\u7801\u6587\u4ef6<\/h4>\n<pre><code class=\"language-bash\">#\u521b\u5efa\u5bc6\u7801\u6587\u4ef6\u9700\u8981\u7528\u5230 htpasswd\r\n[root@web01 ~]# htpasswd -c \/etc\/nginx\/auth_basic lhd # -c\u521b\u5efa\r\nNew password: \r\nRe-type new password: \r\nAdding password for user lhd\r\n\r\n#\u6dfb\u52a0\u4e00\u4e2a\u767b\u5f55\u7528\u6237\r\n[root@web01 ~]# htpasswd \/etc\/nginx\/auth_basic egon # \u4e0d\u52a0-c\u5373\u6dfb\u52a0\r\nNew password: \r\nRe-type new password: \r\nAdding password for user egon\r\n\r\n#\u5bc6\u7801\u6587\u4ef6\u5185\u5bb9\r\n[root@web01 ~]# cat \/etc\/nginx\/auth_basic\r\nlhd:$apr1$A7d4BWYe$HzlIA7pjdMHBDJPuLBkvd\/\r\negon:$apr1$psp0M3A5$601t7Am1BG3uINvuBVbFV0<\/code><\/pre>\n<h4>3\uff09\u914d\u7f6e\u8bbf\u95ee\u767b\u5f55<\/h4>\n<div  class='collapse-block shadow-sm collapse-block-transparent collapsed hide-border-left'><div class='collapse-block-title'><span class='collapse-block-title-inner'>\u8ba4\u8bc1\u6d41\u7a0b<\/span><i class='collapse-icon fa fa-angle-down'><\/i><\/div><div class='collapse-block-body' style='display:none;'><\/p>\n<pre class=\"code\">\u5f53\u4e00\u4e2a\u7f51\u7ad9\u914d\u7f6e\u4e86\u57fa\u7840\u8ba4\u8bc1\uff08Basic Authentication\uff09\uff0cNginx \u4f5c\u4e3a web \u670d\u52a1\u5668\u4f1a\u5bf9\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u8fdb\u884c\u68c0\u67e5\u3002\u5982\u679c\u8bf7\u6c42\u4e2d\u4e0d\u5305\u542b Authorization \u8bf7\u6c42\u5934\uff0c\u670d\u52a1\u5668\u4f1a\u5411\u5ba2\u6237\u7aef\u8fd4\u56de\u4e00\u4e2a 401 Unauthorized \u72b6\u6001\uff0c\u5e76\u4e14\u8fd4\u56de\u4e00\u4e2a WWW-Authenticate \u54cd\u5e94\u5934\uff0c\u63d0\u793a\u9700\u8981\u8fdb\u884c\u8ba4\u8bc1\u3002\r\n\u6d4f\u89c8\u5668\u6536\u5230\u8fd9\u4e2a 401 \u54cd\u5e94\u540e\uff0c\u4f1a\u5f39\u51fa\u4e00\u4e2a\u767b\u5f55\u7a97\u53e3\u8981\u6c42\u7528\u6237\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u7528\u6237\u8f93\u5165\u6b63\u786e\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u540e\uff0c\u6d4f\u89c8\u5668\u4f1a\u5c06\u5b83\u4eec\u8fdb\u884c Base64 \u7f16\u7801\uff0c\u5e76\u5728\u63a5\u4e0b\u6765\u5bf9\u670d\u52a1\u5668\u7684\u6bcf\u4e2a\u8bf7\u6c42\u4e2d\uff0c\u81ea\u52a8\u6dfb\u52a0\u4e00\u4e2a Authorization \u8bf7\u6c42\u5934\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a\r\nCopy\r\nAuthorization: Basic base64(username:password)\r\n\u5728\u60a8\u63d0\u4f9b\u7684\u4f8b\u5b50\u4e2d\uff0cdG9tOjEyMw== \u662f tom:123\uff08\u7528\u6237\u540d:\u5bc6\u7801\uff09\u7684 Base64 \u7f16\u7801\u3002\u6240\u4ee5\u4e00\u65e6\u7528\u6237\u8f93\u5165\u4e86\u8ba4\u8bc1\u4fe1\u606f\uff0c\u6d4f\u89c8\u5668\u5c31\u4f1a\u81ea\u52a8\u5904\u7406\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u5c06\u7f16\u7801\u540e\u7684\u51ed\u8bc1\u4f5c\u4e3a Authorization \u8bf7\u6c42\u5934\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u3002\r\n\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u540e\u4f1a\u89e3\u7801 Authorization \u7684\u503c\uff0c\u9a8c\u8bc1\u7528\u6237\u540d\u548c\u5bc6\u7801\u662f\u5426\u6b63\u786e\uff0c\u6765\u51b3\u5b9a\u662f\u5426\u6388\u6743\u5ba2\u6237\u7aef\u8bbf\u95ee\u8bf7\u6c42\u7684\u8d44\u6e90\u3002\u5982\u679c\u7528\u6237\u540d\u548c\u5bc6\u7801\u9a8c\u8bc1\u5931\u8d25\uff0c\u5ba2\u6237\u7aef\u901a\u5e38\u4f1a\u518d\u6b21\u6536\u5230 401 \u54cd\u5e94\uff0c\u5e76\u91cd\u65b0\u8bf7\u6c42\u8f93\u5165\u51ed\u8bc1\u3002\u5982\u679c\u51ed\u8bc1\u9a8c\u8bc1\u6210\u529f\uff0c\u5219\u4f1a\u6536\u5230\u6240\u8bf7\u6c42\u8d44\u6e90\u7684\u54cd\u5e94\u3002\r\n<\/pre>\n<p><\/div><\/div>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n    access_log \/var\/log\/nginx\/www.autoindex.com.log main;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n        autoindex_exact_size off;\r\n        autoindex_localtime on;\r\n        auth_basic \"egon say hello!\";  # <strong><span style=\"background-color: #ff0000;\">\u7528\u8c37\u6b4c\u6d4f\u89c8\u5668\u9a8c\u8bc1\uff0c\u4e0d\u8981\u7528\u706b\u72d0\u6293\u4e0d\u5230401\u7684\u5305<\/span><\/strong>\r\n        auth_basic_user_file \/etc\/nginx\/auth_basic;\r\n    }\r\n}<\/code><\/pre>\n<h3>4.Nginx\u72b6\u6001\u76d1\u63a7\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\"># ngx_http_stub_status_module\r\n\r\nngx_http_stub_status_module\u6a21\u5757\u63d0\u4f9b\u5bf9nginx\u57fa\u672c\u72b6\u6001\u4fe1\u606f\u7684\u8bbf\u95ee\u3002\r\n\u5e94\u4f7f\u7528--with-http_stub_status_module\u914d\u7f6e\u53c2\u6570\u542f\u7528\u5b83\uff0c1.26\u7248\u9ed8\u8ba4\u542f\u7528\uff0c\u53ef\u7528nginx -V\u67e5\u770b<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">Syntax: stub_status;\r\nDefault:    \u2014\r\nContext:    server, location<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n    access_log \/var\/log\/nginx\/www.autoindex.com.log main;\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n\r\n    location \/download {\r\n        root \/code\/autoindex;\r\n        autoindex on;\r\n        autoindex_exact_size off;\r\n        autoindex_localtime on;\r\n        auth_basic \"\u6027\u611f\u8377\u5b98\u5728\u7ebf\u53d1\u724c\uff01\uff01\uff01\";\r\n        auth_basic_user_file \/etc\/nginx\/auth_basic;\r\n    }\r\n\r\n    location = \/basic_status {\r\n        stub_status;\r\n    }\r\n}<\/code><\/pre>\n<h4>3\uff09\u8bbf\u95ee<\/h4>\n<pre><code class=\"language-bash\">#\u8bbf\u95ee http:\/\/www.autoindex.com\/basic_status\r\n\r\n#nginx\u4e03\u79cd\u72b6\u6001\r\nActive connections: 2 \r\nserver accepts handled requests\r\n 4 4 21 \r\nReading: 0 Writing: 1 Waiting: 1 \r\n\r\n# \u7d2f\u8ba1\u503c\r\nActive connections      #\u5f53\u524d\u6d3b\u8dc3\u7684\u8fde\u63a5\u6570\r\n[root@web01 \/usr\/share\/nginx\/html]# netstat -ant |grep 80\r\ntcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN \r\ntcp 0 0 192.168.71.112:80 192.168.71.7:65491 ESTABLISHED\r\ntcp 0 0 192.168.71.112:80 192.168.71.7:65492 ESTABLISHED\r\n\r\naccepts                 #nginx\u542f\u52a8\u5f00\u59cb\u7b97\uff0c\u7d2f\u8ba1\u63a5\u6536\u7684TCP\u8fde\u63a5\u603b\u6570\r\nhandled                 #\u7d2f\u8ba1\u6210\u529f\u7684TCP\u8fde\u63a5\u6570\r\nrequests                #\u7d2f\u8ba1\u6210\u529f\u7684\u8bf7\u6c42\u6570\r\nReading                 #\u5f53\u524d0\u4e2a\u94fe\u63a5\u6b63\u5728\u8bfb\u8bf7\u6c42\r\nWriting                 #\u5f53\u524d1\u4e2a\u94fe\u63a5\u6b63\u5728\u54cd\u5e94\u6570\u636e\u7ed9\u5ba2\u6237\u7aef\r\nWaiting                 #\u5f53\u524d\u7b49\u5f85\u7684\u8bf7\u6c42\u6570\uff0c\u5373\u5f53\u524d\u5904\u4e8ekeep-alive\u72b6\u6001\u7684\u8fde\u63a5\u6570\r\n\r\n# \u6ce8\u610f, \u4e00\u6b21TCP\u7684\u8fde\u63a5\uff0c\u53ef\u4ee5\u53d1\u8d77\u591a\u6b21http\u7684\u8bf7\u6c42, \u5982\u4e0b\u53c2\u6570\u53ef\u914d\u7f6e\u8fdb\u884c\u9a8c\u8bc1\r\nkeepalive_timeout  0;   # \u7c7b\u4f3c\u4e8e\u5173\u95ed\u957f\u8fde\u63a5\r\nkeepalive_timeout  65;  # 65s\u6ca1\u6709\u6d3b\u52a8\u5219\u65ad\u5f00\u8fde\u63a5<\/code><\/pre>\n<h3>5.\u8fde\u63a5\u9650\u5236\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\"># ngx_http_limit_conn_module<\/code><\/pre>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u8bbe\u7f6e\u9650\u5236\u7684\u7a7a\u95f4\r\nSyntax: limit_conn_zone key zone=name:size;\r\nDefault:    \u2014\r\nContext:    http\r\n\r\nlimit_conn_zone     #\u8bbe\u7f6e\u7a7a\u95f4\u7684\u6a21\u5757\r\nkey                 #\u6307\u5b9a\u7a7a\u95f4\u5b58\u50a8\u7684\u5185\u5bb9\r\nzone                #\u6307\u5b9a\u7a7a\u95f4\r\n=name               #\u7a7a\u95f4\u540d\u5b57\r\n:size;              #\u7a7a\u95f4\u7684\u5927\u5c0f\r\n\r\n#\u8c03\u7528\u9650\u5236\u7684\u7a7a\u95f4\r\nSyntax: limit_conn zone number;\r\nDefault:    \u2014\r\nContext:    http, server, location\r\n\r\nlimit_conn          #\u8c03\u7528\u7a7a\u95f4\u7684\u6a21\u5757\r\nzone                #\u7a7a\u95f4\u7684\u540d\u5b57\r\nnumber;             #\u6307\u5b9a\u53ef\u4ee5\u540c\u65f6\u8fde\u63a5\u7684\u6b21\u6570<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\nlimit_conn_zone $remote_addr zone=conn_zone:10m;    #\u8bbe\u7f6e\u4e00\u4e2a\u5b58\u50a8ip\u5730\u5740\uff0c\u7a7a\u95f4\u540d\u5b57\u4e3aconn_zone,\u7a7a\u95f4\u5927\u5c0f\u4e3a10M\u7684\u7a7a\u95f4\r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;;\r\n    limit_conn conn_zone 1;     #\u8c03\u7528conn_zone\u7a7a\u95f4\uff0c\u9650\u5236\u6bcf\u4e2aip\u540c\u65f6\u53ea\u80fd\u8fde\u63a5\u4e00\u6b21\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n}<\/code><\/pre>\n<p><span style=\"background-color: #ff0000;\">\u6d4b\u8bd5\u7684\u65f6\u5019\u8bf7\u628akeepalive_timeout\u8bbe\u7f6e\u4e3a0\uff0c\u6392\u9664\u5e72\u6270<\/span><\/p>\n<h3>6.\u8bf7\u6c42\u9650\u5236\u6a21\u5757<\/h3>\n<h4>1\uff09\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-bash\">#\u8bbe\u7f6e\u7a7a\u95f4\u7684\u8bed\u6cd5\r\nSyntax: limit_req_zone key zone=name:size rate=rate [sync];\r\nDefault:    \u2014\r\nContext:    http\r\n\r\nlimit_req_zone          #\u8bbe\u7f6e\u7a7a\u95f4\u7684\u6a21\u5757\r\nkey                     #\u7a7a\u95f4\u5b58\u50a8\u7684\u5185\u5bb9\r\nzone                    #\u6307\u5b9a\u7a7a\u95f4\r\n=name                   #\u7a7a\u95f4\u7684\u540d\u5b57\r\n:size                   #\u7a7a\u95f4\u7684\u5927\u5c0f\r\nrate=rate [sync];       #\u8bfb\u5199\u901f\u7387\r\n\r\n#\u8c03\u7528\u7684\u8bed\u6cd5\r\nSyntax: limit_req zone=name [burst=number] [nodelay | delay=number];\r\nDefault:    \u2014\r\nContext:    http, server, location\r\n\r\nlimit_req               #\u8c03\u7528\u63a7\u4ef6\u6a21\u5757\r\nzone=name               #\u6307\u5b9a\u7a7a\u95f4=\u7a7a\u95f4\u7684\u540d\u5b57\r\n[burst=number]          #\u5141\u8bb8\u591a\u8bf7\u6c42\u51e0\u6b21\r\n[nodelay | delay=number]; #\u5ef6\u65f6<\/code><\/pre>\n<h4>2\uff09\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# vim \/etc\/nginx\/conf.d\/www.autoindex.com.conf \r\n\r\nlimit_conn_zone $remote_addr zone=conn_zone:10m;\r\nlimit_req_zone $remote_addr zone=req_zone:10m rate=1r\/s;    #\u8bbe\u7f6e\u4e00\u4e2a\u50a8\u5b58ip\u5730\u5740\uff0c\u50a8\u5b58\u5927\u5c0f\u4e3a10m\uff0c\u7a7a\u95f4\u540d\u5b57req_zone\uff0c\u4e00\u79d2\u53ea\u80fd\u8bf7\u6c42\u4e00\u6b21\u7684\u7a7a\u95f4\u3002\r\nserver {\r\n    listen 80;\r\n    server_name www.autoindex.com;\r\n    charset utf8;\r\n    limit_conn conn_zone 1;\r\n    limit_req zone=req_zone;    #\u8c03\u7528\u7a7a\u95f4\u540d\u5b57\u662freq_zone\u7684\u7a7a\u95f4\r\n    #limit_req zone=req_zone burst=5 nodelay;           #\u8c03\u7528\u7a7a\u95f4\u540d\u5b57\u662freq_zone\u7684\u7a7a\u95f4\uff0c\u6700\u5927\u9650\u5ea6\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u4e94\u6b21\uff0c\u6ca1\u6709\u5ef6\u8fdf\r\n\r\n    location \/ {\r\n        root \/code\/autoindex;\r\n        index index.html;\r\n    }\r\n}<\/code><\/pre>\n<h4>3\uff09\u6d4b\u8bd5<\/h4>\n<pre><code class=\"language-bash\">[root@web01 ~]# ab -n 20000 -c 20 http:\/\/www.autoindex.com\/index.html \r\n        -n        #\u8bf7\u6c42\u7684\u6b21\u6570\r\n        -c        #\u4e00\u6b21\u8bf7\u6c42\u5e76\u53d1\u7684\u6b21\u6570<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>nginx\u4e00\u4e9b\u5e38\u7528\u6a21\u5757 \u6a21\u5757\u5f88\u591a\uff0c\u5b66\u4e0d\u5b8c\u7684\uff0c\u7785\u4e00\u773c\uff0c\u6709\u4e2a\u57fa\u672c\u5370\u8c61\u5373\u53ef 1.\u76ee\u5f55\u7d22\u5f15\u6a21\u5757 # ngx_http_ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9573"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9573"}],"version-history":[{"count":8,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9573\/revisions"}],"predecessor-version":[{"id":11095,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9573\/revisions\/11095"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}