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>