Apache HTTP Server(三)--配置片段

来源:岁月联盟 编辑:exp 时间:2012-06-26
Apache HTTP Server(三)--配置片段 基本容器
 <IfDefine>只在命令行参数里有相应定义时才会应用。比如:<IfDefine ClosedForNow>    Redirect / http://otherserver.example.com/</IfDefine>只有以Apache2 -DClosedForNow命令启动时才会应用。 <IfModule>只在相应模块可用时才应用。比如:<IfModule mod_mime_magic.c>    MimeMagicFile conf/magic</IfModule>只在模块mod_mime_magic可用时才有效。 <IfVersion>根据服务器版本应用。比如:<IfVersion >= 2.4>    # this happens only in versions greater or    # equal 2.4.0.  www.2cto.com  </IfVersion> 文件系统容器<Directory>指定一个目录并把指令应用到该目录以及它所有的子目录里,和.htaccess文件的作用相同。
例如:<Directory /var/web/dir1>    Options +Indexes</Directory> <File>指定文件名,而不管它在哪个目录里。例如:<Files private.html>    Require all denied</Files> <Directory>和<Files>也可以联合使用:<Directory /var/web/dir1>    <Files private.html>        Require all denied    </Files></Directory>它应用于指定目录及其子目录里的所有名为private.html的文件。 web空间容器与文件系统不同,这主要是指明URL内的路径。例如:<LocationMatch ^/private>    Require all denied</Location>它 可以匹配所有以/private开头的URL路径,比如:http://yoursite.example.com/private、http: //yoursite.example.com/private123、和http://yoursite.example.com/private /dir/file.html等。  www.2cto.com   <Location>所指的文件可能不存在于文件系统里,它可能是根据数据库生成的。一般原则是:可以用<Directory>和<File>表示的,尽量不要使用<Location>。 在路径出现交叠时,我们要注意顺序,例如我们必须这样写:<Location /foo></Location><Location /foo/bar></Location> 相对的,<Alias>应该使用相反的顺序:Alias /foo/bar /srv/www/uncommon/barAlias /foo /srv/www/common/foo ProxyPass也是如此:ProxyPass /special-area http://special.example.com smax=5 max=10ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On 通配符和正则表达式<Directory>、<Files>、和<Location>里可以使用shell风格的通配符:“*” 表示任意字符串;“?”表示任意单个字符;“[seq]”表示任意出现在seq里的字符。“/”不会匹配任何通配符,必须明确指明。比如:<Directory /home/*/public_html>    Options Indexes</Directory>  www.2cto.com   这些指令还有相应的正则表达式的指令:<DirectoryMatch>、<FilesMatch>、和<LocationMatch>。比如:<FilesMatch /.(?i:gif|jpe?g|png)$>    Require all denied</FilesMatch> 逻辑表达式<If>指令根据逻辑表达式来选择应用。例如:<If "!(%{HTTP_REFERER} -strmatch 'http://www.example.com/*')">    Require all denied</If>当HTTP Referer头不以http://www.example.com/开头时启用。 <If>可以内嵌在<Directory>、<File>、和<Location>里。 虚拟主机<VirtualHost>容器针对特定的主机。 代理<Proxy>和<ProxyMatch>容器,应用于通过mod_proxy的代理服务器的站点。例如:<Proxy http://www.example.com/*>    Require all granted</Proxy>阻止代理服务器被用来访问http://www.example.com/。  www.2cto.com  有效的指令通常在<Directory>里有效的指令也可以 在<DirectoryMatch>、<Files>、<FilesMatch>、<Location>、<LocationMatch>、<Proxy>、 和<ProxyMatch>里使用。但也有以下例外:
 AllowOverride只能在<Directory>里使用。FollowSymLinks和SymLinksIfOwnerMatch选项只在<Directory>和.htaccess文件里使用。Options指令不能在<Files>和<FilesMatch>里使用。  作者 yourtommy