標籤:server 空間 項目
apache用Directory
說明 封裝一組指令,使之僅對檔案空間中的某個目錄及其子目錄生效
文法 <Directory directory-path> ... </Directory>
範圍 server config, virtual host
狀態 核心(C)
模組 core
apache用DirectoryMatch過濾不想顯示的檔案或者目錄
執行個體如下,在我的一個樣本項目中,我不想顯示所有的.c檔案,可以通過如下設定:
Alias /sample /opt/projects/Sample
<Directory /opt/projects/Sample>
Options Indexes FollowSymLinks MultiViews
Order Allow,Deny
Allow from all
</Directory>
<DirectoryMatch \.c>
Deny from all
</DirectoryMatch>
使用<Directory>… </Directory>設定指定目錄的存取權限,其中可包含:
Options
AllowOverride
Order
Allow
Deny
五個屬性。
Options屬性
Options FollowSymLinks Indexes MultiViews
Options可以組合設定下列選項:
All:使用者可以在此目錄中作任何事情。
ExecCGI:允許在此目錄中執行CGI程式。
FollowSymLinks:伺服器可使用符號連結指向的檔案或目錄。
Indexes:伺服器可產生此目錄的檔案清單。
None:不允許訪問此目錄。
AllowOverride
AllowOverride None
AllowOverride會根據設定的值決定是否讀取目錄中的.htaccess檔案,來改變原來所設定的許可權。
All:讀取.htaccess檔案的內容,修改原來的存取權限。
None:不讀取.htaccess檔案
為避免使用者自行建立.htaccess檔案修改存取權限,http.conf檔案中預設設定每個目錄為: AllowOverride None。
AccessFileName
AccessFileName filename
AccessFileName指令用於指定保護目錄設定檔案的檔案名稱,預設值為“.htaccess”。
AccessFileName .acl
Allow
設定允許訪問Apache伺服器的主機
Allow from all
允許所有主機的訪問
Allow from 202.96.0.97 202.96.0.98
允許來自指定IP地址主機的訪問
<VirtualHost *:80>
ServerAdmin test.com
DocumentRoot "/usr/local/apache/htdocs"
ServerName test.com
DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3
ServerAlias www.dummy-host.example.com test1.com testnet.com
ErrorLog "/var/http/logs/test-Error_log"
CustomLog "logs/test.com-access_log" combined_with_cookie
訪問/usr/local/apache/htdocs下目錄需要使用者密碼登入
<Directory "/usr/local/apache/htdocs"> #把目錄下的所以檔案進行對外訪問
# Options FollowSymLinks
# AllowOverride All
# Order Allow,Deny
# Allow from all
# RewriteEngine on
# RewriteRule ^a(.*).html$ /test.php?id=$1
AuthType Basic
AuthName Authorize
AuthUserFile /usr/local/apache/conf/extra/password 訪問需要使用者密碼登入
require user ren
#把所有的a.開頭的.html檔案跳轉到test.php檔案下 $1是 ^a(.*).html$
</Directory>
</VirtualHost>
放開/usr/local/apache/htdocs/bbs目錄能直接存取
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/bbs"
ServerName zhang.com
DirectoryIndex index.html index.shtml index.cgi index.php index.phtml index.php3
ServerAlias www.dummy-host.example.com test1.com testnet.com
ErrorLog "/var/http/logs/test-Error_log"
CustomLog "logs/test.com-access_log" combined_with_cookie
<DirectoryMatch "/usr/local/apache/htdocs/bbs">放開
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</DirectoryMatch>
</VirtualHost>
apache目錄限制