Apache實現訪問控制的配置指令包括以下三種:(1)order指令:用於指定執行容許訪問控制規則或者拒絕訪問控制規則的順序。order只能設置爲Order allow,deny或Order deny,allow,分別用來代表用戶先設置容許的訪問地址仍是先設置禁止訪問的地址。Order選項用於定義缺省的訪問權限與Allow和Deny語句的處理順序。Allow和Deny語句能夠針對客戶機的域名或IP地址進行設置,以決定哪些客戶機可以訪問服務器。Order語句設置的兩種值的具體含義以下:javascript
◆allow, deny:缺省禁止全部客戶機的訪問,且Allow語句在Deny語句以前被匹配。若是某條件既匹配Deny語句又匹配Allow語句,則Deny語句會起做用(由於Deny語句覆蓋了Allow語句)。php
◆deny, allow:缺省容許全部客戶機的訪問,且Deny語句在Allow語句以前被匹配。若是某條件既匹配Deny語句又匹配Allow語句,則Allow語句會起做用(由於Allow語句覆蓋了Deny語句)。css
(2)allow指令:指明容許訪問的地址或地址序列。如allow from all指令代表容許全部IP來的訪問請求。html
(3)deny指令:指明禁止訪問的地址或地址序列。如deny from all指令代表禁止全部IP來的訪問請求。java
增長訪問控制配置apache
[root@chy ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/data/wwwroot/111.com" ServerName www.111.com ServerAlias www.exaple.com 222.com #<Directory /data/wwwroot/111.com> #<filesMatch 123.php> #AllowOverride AuthConfig #AuthName "111.com user auth" #AuthType Basic #AuthUserFile /data/.htpasswd #require valid-user #</FilesMatch> #</Directory> <Directory /data/wwwroot/www.123.com/admin/> Order deny,allow Deny from all Allow from 127.0.0.1 </Directory> # <IfModule mod_rewrite.c> # RewriteEngine on #RewriteCond %{HTTP_HOST} !^111.com$ #RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] # </IfModule> #<IfModule mod_expires.c> #ExpiresActive on #ExpiresByType image/gif "access plus 1 days" #ExpiresByType image/jpeg "access plus 24 hours" #ExpiresByType image/png "access plus 24 hours" #ExpiresByType text/css "now plus 2 hour" #ExpiresByType application/x-javascript "now plus 2 hours" #ExpiresByType application/javascript "now plus 2 hours" #ExpiresByType application/x-shockwave-flash "now plus 2 hours" # ExpiresDefault "now plus 0 min" #</IfModule> <Directory /data/wwwroot/111.com> SetEnvIfNoCase Referer "http://444.com" local_ref SetEnvIfNoCase Referer "http://123.com" local_ref #SetEnvIfNoCase Referer "^$" local_ref <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)"> Order Allow,Deny Allow from env=local_ref </filesmatch> </Directory> ErrorLog "logs/111.com-error_log" SetEnvIf Request_URI ".*\.gif$" img SetEnvIf Request_URI ".*\.jpg$" img SetEnvIf Request_URI ".*\.png$" img SetEnvIf Request_URI ".*\.bmp$" img SetEnvIf Request_URI ".*\.swf$" img SetEnvIf Request_URI ".*\.js$" img SetEnvIf Request_URI ".*\.css$" img CustomLog "logs/111.com-access_log" combined env=!img </VirtualHost> (如上配置,主要的配置以下:<Directory /data/wwwroot/111.com/admin/> Order deny,allow(這個是按照這一行的順序,先是deny,後是allow,最後的結果是allow。不看下面的前後順序) Deny from all Allow from 127.0.0.1 </Directory> (這個要放在防盜鏈的上面) [root@chy ~]# mkdir -p /data/wwwroot/111.com/admin/ (建立一個admin目錄) [root@chy admin]# vim index.php [root@chy admin]# cat index.php djaog (在index.php裏面寫入內容,而後查看) [root@chy ~]# curl -x127.0.0.1:80 www.111.com/admin/index.php -I HTTP/1.1 200 OK Date: Thu, 03 Aug 2017 01:23:05 GMT Server: Apache/2.4.27 (Unix) PHP/5.6.30 X-Powered-By: PHP/5.6.30 Content-Type: text/html; charset=UTF-8 (用curl測試,) [root@chy ~]# curl -x127.0.0.1:80 www.111.com/admin/index.php djaog [root@chy ~]# curl -x192.168.212.10:80 www.111.com/admin/index.php <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /admin/index.php on this server.<br /> </p> </body></html> (用本機的ip進行測試)