{"id":2011,"date":"2013-11-29T14:58:12","date_gmt":"2013-11-29T06:58:12","guid":{"rendered":"http:\/\/www.chenlianfu.com\/?p=2011"},"modified":"2013-11-29T15:07:07","modified_gmt":"2013-11-29T07:07:07","slug":"apache%e7%9a%84%e7%bd%91%e9%a1%b5%e5%ae%89%e5%85%a8%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"http:\/\/www.chenlianfu.com\/?p=2011","title":{"rendered":"apache\u7684\u7f51\u9875\u5b89\u5168\u8bbe\u7f6e"},"content":{"rendered":"<h1>1. \u9650\u5236IP\u8bbf\u95ee<\/h1>\n<p>\u4f7f\u7528deny\u548callow\u6765\u8bbe\u5b9a\u5141\u8bb8\u548c\u4e0d\u5141\u8bb8\u8bbf\u95ee\u7f51\u9875\u7684IP\u6bb5\u3002<\/p>\n<pre>\r\nOrder deny,allow\uff1a\u4ee5 deny \u4f18\u5148\u5904\u7406\uff0c\u4f46\u6ca1\u6709\u5199\u5165\u89c4\u5219\u7684\u5219\u9ed8\u8ba4\u4e3a allow \u3002\u5e38\u7528\u4e8e\uff1a\u62d2\u7edd\u6240\u6709\uff0c\u5f00\u653e\u7279\u5b9a\u7684\u6761\u4ef6\uff1b\r\nOrder allow,deny\uff1a\u4ee5 allow \u4e3a\u4f18\u5148\u5904\u7406\uff0c\u4f46\u6ca1\u6709\u5199\u5165\u89c4\u5219\u7684\u5219\u9ed8\u8ba4\u4e3a deny\u3002 \u5e38\u7528\u4e8e\uff1a\u5f00\u653e\u6240\u6709\uff0c\u62d2\u7edd\u7279\u5b9a\u7684\u6761\u4ef6\u3002\r\n\u5982\u679c allow \u4e0e deny \u7684\u89c4\u5219\u5f53\u4e2d\u6709\u91cd\u590d\u7684\uff0c\u5219\u4ee5\u9884\u8bbe\u7684\u60c5\u51b5 (Order \u7684\u89c4\u8303) \u4e3a\u4e3b\u3002\r\n<\/pre>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8fd9\u6837\u5199\uff0c\u7528\u4e8e\u4e0d\u5141\u8bb8\u67d0\u4e9bIP\u7684\u8bbf\u95ee\uff1a<\/p>\n<pre>\r\n&lt;Directory \"\/var\/www\/html\"&gt;\r\n    Options FollowSymLinks\r\n    AllowOverride None\r\n    Order allow,deny\r\n    allow from all\r\n    deny from 192.168.1.0\/24\r\n    deny from .gov.tw\r\n&lt;\/Directory&gt;\r\n<\/pre>\n<h1>2. \u8bbe\u7f6e\u4fdd\u62a4\u7f51\u9875\u7684\u7528\u6237\u540d\u5bc6\u7801\u8bbf\u95ee<\/h1>\n<h2>2.1 \u4fee\u6539\/etc\/httpd\/conf\/httpd.conf\u6587\u4ef6<\/h2>\n<pre>\r\n[root@linux ~]# vi \/etc\/httpd\/conf\/httpd.conf\r\n# \u786e\u5b9a\u5e95\u4e0b\u8fd9\u51e0\u884c\u662f\u5b58\u5728\u7684\uff01\r\nAccessFileName .htaccess\r\n&lt;Files ~ \"^\\.ht\"&gt;\r\n    Order allow,deny\r\n    Deny from all\r\n&lt;\/Files&gt;\r\n\r\n# \u5728\u67d0\u4e2a\u4e0d\u53d7\u5f71\u54cd\u7684\u5730\u65b9\u52a0\u5165\u8fd9\u4e00\u6bb5\uff1a\r\n&lt;Directory \"\/var\/www\/html\/protect\"&gt;\r\n    AllowOverride AuthConfig\r\n    Order allow,deny\r\n    Allow from all\r\n&lt;\/Directory&gt;\r\n\r\n[root@linux ~]# apachectl restart  <==\u91cd\u65b0\u542f\u52a8\uff0c\u4e0d\u8981\u5fd8\u8bb0\u4e86\uff01\r\n<\/pre>\n<h2>2.2 \u5728\u4fdd\u62a4\u76ee\u5f55\u4e0b\u5efa\u7acb.htaccess \u6863\u6848<\/h2>\n<pre>\r\n[root@linux ~]# cd \/var\/www\/html\/protect\r\n[root@linux ~]# vi .htaccess\r\n# \u53ea\u8981\u52a0\u5165\u5e95\u4e0b\u8fd9\u51e0\u884c\u5373\u53ef\r\nAuthName     \"Protect test by .htaccess\"\r\nAuthtype     Basic\r\nAuthUserFile \/var\/www\/apache.passwd\r\nrequire user test\r\n<\/pre>\n<h2>2.3 \u5efa\u7acb\u5bc6\u7801\u6863\u6848 htpasswd<\/h2>\n<p>Apache \u9ed8\u8ba4\u8bfb\u53d6\u7684\u8d26\u53f7\/\u5bc6\u7801\u8bbe\u5b9a\u6570\u636e\u662f\u7531 htpasswd \u6240\u5efa\u7acb\u7684\uff0c\u8fd9\u4e2a\u6307\u4ee4\u7684\u8bed\u6cd5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre>\r\n[root@linux ~]# htpasswd [-c] \u5bc6\u7801\u6587\u4ef6\u6587\u4ef6\u540d \u7528\u6237\u8d26\u53f7\r\n\u53c2\u6570\uff1a\r\n-c \uff1a\u5efa\u7acb\u540e\u9762\u7684\u5bc6\u7801\u6863\u6848\u3002\u5982\u679c\u8be5\u6863\u6848\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u539f\u672c\u7684\u6570\u636e\u4f1a\u88ab\u5220\u9664\uff01\r\n     \u6240\u4ee5\u5982\u679c\u53ea\u662f\u8981\u65b0\u589e\u4f7f\u7528\u8005(\u6863\u6848\u5df2\u5b58\u5728\u65f6)\uff0c\u4e0d\u5fc5\u52a0\u4e0a -c \u7684\u53c2\u6570\uff01\r\n\r\n1. \u5efa\u7acb apache.passwd \uff0c\u8d26\u53f7\u4e3a test\r\n[root@linux ~]# htpasswd -c \/var\/www\/apache.passwd test\r\nNew password:  <==\u8fd9\u91cc\u8f93\u5165\u4e00\u6b21\u5bc6\u7801\uff0c\u6ce8\u610f\uff0c\u5c4f\u5e55\u4e0d\u4f1a\u6709\u4efb\u4f55\u8baf\u606f\u3002\r\nRe-type new password:  <==\u8fd9\u91cc\u518d\u8f93\u5165\u4e00\u6b21\r\nAdding password for user test\r\n\r\n[root@linux ~]# cat \/var\/www\/apache.passwd\r\ntest:FIquw\/..iS4yo   <==\u60a8\u77a7\u77a7\uff01\u5df2\u7ecf\u5efa\u7acb\u4e00\u4e2a\u65b0\u4f7f\u7528\u8005\uff01\r\n\r\n2. \u5728\u5df2\u5b58\u5728\u7684 apache.passwd \u5185\u589e\u52a0 test1 \u8fd9\u4e2a\u8d26\u53f7\uff1a\r\n[root@linux ~]# htpasswd \/var\/www\/apache.passwd test1\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u9650\u5236IP\u8bbf\u95ee \u4f7f\u7528deny\u548callow\u6765\u8bbe\u5b9a\u5141\u8bb8\u548c\u4e0d\u5141\u8bb8\u8bbf\u95ee\u7f51\u9875\u7684IP\u6bb5\u3002 &hellip; <a href=\"http:\/\/www.chenlianfu.com\/?p=2011\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/2011"}],"collection":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2011"}],"version-history":[{"count":5,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/2011\/revisions"}],"predecessor-version":[{"id":2016,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/2011\/revisions\/2016"}],"wp:attachment":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2011"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}