{"id":622,"date":"2020-03-05T01:24:29","date_gmt":"2020-03-04T17:24:29","guid":{"rendered":"https:\/\/aichh.com\/?p=622"},"modified":"2020-03-05T01:33:46","modified_gmt":"2020-03-04T17:33:46","slug":"nginx%e8%ae%be%e7%bd%ae%e8%ba%ab%e4%bb%bd%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/aichh.com\/622.html","title":{"rendered":"Nginx\u8bbe\u7f6e\u8eab\u4efd\u9a8c\u8bc1"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5bf9\u67d0\u4e9b\u5185\u5bb9\u7684\u8bbf\u95ee\u8fdb\u884c\u9650\u5236\uff0c\u5728Nginx\u4e2d\u4e5f\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u9650\u5236\u63aa\u65bd\uff0c\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u9650\u5236\u63aa\u65bd\uff1a<\/p>\n<p><strong>1.\u8bbf\u95ee\u8eab\u4efd\u9a8c\u8bc1<\/strong><\/p>\n<p>\u5728Nginx\u7684\u63d2\u4ef6\u6a21\u5757\u4e2d\u6709\u4e00\u4e2a\u6a21\u5757ngx_http_auth_basic_module\u53ef\u4ee5\u8981\u6c42\u7528\u6237\u8fdb\u884c\u8eab\u4efd\u8ba4\u8bc1\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0bnginx\u5df2\u7ecf\u5b89\u88c5\u4e86\u8fd9\u4e2a\u6a21\u5757 \u3002\u53ef\u901a\u8fc7\u547d\u4ee4.\/nginx -V\u67e5\u770b\u662f\u5426\u6709\u6b64\u6a21\u5757\u3002<\/p>\n<p>\u5b89\u88c5\u540e\u53ea\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u6b65\u9aa4\u5373\u53ef\u5b9e\u73b0\uff1a<\/p>\n<p>\u9996\u5148\u521b\u5efa\u5bc6\u94a5\u6587\u4ef6:<\/p>\n<div class=\"cnblogs_code\">\n<pre>\u3000\u3000yum install -y httpd-tools\r\n\u3000\u3000htpasswd -bc \/www\/wwwroot\/htpasswd.users username password\r\n   cat \/usr\/nginx\/conf\/htpasswd.users<\/pre>\n<\/div>\n<p>\u914d\u7f6enginx\uff1a(\u5b9d\u5854\u7684\u8bdd\u52a0\u4e0b\u9762\u7684<span style=\"color: #ff0000;\">auth<\/span>\u4e24\u884c\u5230\u4f2a\u9759\u6001\u4e2d\u5373\u53ef)<a title=\"\u590d\u5236\u4ee3\u7801\">\u00a0<\/a><\/p>\n<div class=\"cnblogs_code\">\n<pre>\u3000\u3000server \r\n\u3000\u3000{\r\n    \u3000\u3000listen 80;\r\n    \u3000\u3000server_name 192.168.1.1;\r\n    \u3000\u3000<span style=\"color: #ff0000;\">auth_basic \"Restricted Access\";\r\n    \u3000\u3000auth_basic_user_file \/www\/wwwroot\/htpasswd.users;<\/span>\r\n    \u3000\u3000location \/ \r\n    \u3000\u3000{\r\n        \u3000\u3000proxy_pass http:\/\/192.168.1.2:5601;\r\n    \u3000\u3000}\r\n\u3000\u3000}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\">\u00a0<\/a><\/span><\/div>\n<\/div>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\u91cd\u542fnginx\u670d\u52a1\u5373\u53ef\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u8f93\u5165\u6846\u8f93\u5165\u8bbe\u7f6e\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u5373\u53ef\uff1a<\/p>\n<p><a href=\"https:\/\/aichh.com\/wp-content\/uploads\/2020\/03\/1583342917-5123-20180129155244796-1776260815.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aichh.com\/wp-content\/uploads\/2020\/03\/1583342917-5123-20180129155244796-1776260815.png\" width=\"788\" height=\"253\" alt=\"Nginx\u8bbe\u7f6e\u8eab\u4efd\u9a8c\u8bc1 \u7ecf\u9a8c\u6559\u7a0b \u7b2c1\u5f20\" title=\"Nginx\u8bbe\u7f6e\u8eab\u4efd\u9a8c\u8bc1 \u7ecf\u9a8c\u6559\u7a0b \u7b2c1\u5f20-AiCHH Ideas\" ><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u9650\u5236IP\u8bbf\u95ee<\/strong><\/p>\n<p>\u5728nginx.conf\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\u53ef\u5b9e\u73b0\u5168\u5c40\u9650\u5236\uff0c\u4e5f\u53ef\u5c06\u6b64\u914d\u7f6e\u653e\u5230server\u4e2d\u6216location\u4e2d\uff0c\u653e\u5230server\u4e2d\u53ea\u9488\u5bf9\u7ad9\u70b9\u8fdb\u884c\u9650\u5236\uff0clocation\u4e2d\u53ea\u9488\u5bf9\u5339\u914d\u7684url\u8fdb\u884c\u9650\u5236\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>\u3000\u3000allow 192.168.1.1;  #\u5141\u8bb8\u7684IP\r\n\u3000\u3000deny  192.168.1.2\uff1b\r\n\u3000\u3000deny all;<\/pre>\n<\/div>\n<p>\u53ef\u6dfb\u52a0\u591a\u6761allow\u6216deny,deny all\u7ed3\u5c3e\u8868\u793a\u9664\u4e86\u4e0a\u9762allow\u7684\u5176\u4ed6\u90fd\u7981\u6b62\uff0cdeny all;deny \u4e00\u5b9a\u8981\u52a0\u4e00\u4e2aip\uff0c\u5426\u5219\u76f4\u63a5\u8df3\u8f6c\u5230403\uff0c\u4e0b\u9762\u7684\u89c4\u5219\u5c06\u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.\u9650\u5236\u67d0\u4e9bip\u5728\u540c\u4e00\u65f6\u95f4\u6bb5\u5185\u7684\u8bbf\u95ee\u6b21\u6570<\/strong><\/p>\n<p>nginx\u53ef\u4ee5\u901a\u8fc7HttpLimitReqModul\u548cHttpLimitZoneModule\u914d\u7f6e\u6765\u9650\u5236ip\u5728\u540c\u4e00\u65f6\u95f4\u6bb5\u7684\u8bbf\u95ee\u6b21\u6570.<\/p>\n<p>HttpLimitReqModul\u7528\u6765\u9650\u5236\u8fde\u5355\u4f4d\u65f6\u95f4\u5185\u8fde\u63a5\u6570\u7684\u6a21\u5757\uff0c\u4f7f\u7528limit_req_zone\u548climit_req\u6307\u4ee4\u914d\u5408\u4f7f\u7528\u6765\u8fbe\u5230\u9650\u5236\u3002\u4e00\u65e6\u5e76\u53d1\u8fde\u63a5\u8d85\u8fc7\u6307\u5b9a\u6570\u91cf\uff0c\u5c31\u4f1a\u8fd4\u56de503\u9519\u8bef\u3002HttpLimitConnModul\u7528\u6765\u9650\u5236\u5355\u4e2aip\u7684\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u4f7f\u7528limit_zone\u548climit_conn\u6307\u4ee4.<\/p>\n<p>\u8fd9\u4e24\u4e2a\u6a21\u5757\u7684\u533a\u522b\u524d\u4e00\u4e2a\u662f\u5bf9\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u8fde\u63a5\u6570\u9650\u5236\uff0c\u540e\u8005\u662f\u5bf9\u540c\u4e00\u65f6\u523b\u7684\u8fde\u63a5\u6570\u9650\u5236.<\/p>\n<p>\u8bf7\u53c2\u8003\uff1ahttps:\/\/www.cnblogs.com\/aoniboy\/p\/4730354.html<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5bf9\u67d0\u4e9b\u5185\u5bb9\u7684\u8bbf\u95ee\u8fdb\u884c\u9650\u5236\uff0c\u5728Nginx\u4e2d\u4e5f\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u9650\u5236\u63aa\u65bd\uff0c\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u9650\u5236\u63aa\u65bd\uff1a 1.\u8bbf\u95ee\u8eab\u4efd\u9a8c\u8bc1 \u5728Nginx\u7684\u63d2\u4ef6\u6a21\u5757\u4e2d\u6709\u4e00\u4e2a\u6a21\u5757ngx_http_auth_basic \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[127,62,128],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-jiaocheng","tag-htpasswd","tag-nginx","tag-128"],"views":442,"_links":{"self":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/comments?post=622"}],"version-history":[{"count":7,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/aichh.com\/api\/wp\/v2\/posts\/622\/revisions\/630"}],"wp:attachment":[{"href":"https:\/\/aichh.com\/api\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aichh.com\/api\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}