在apache2.2下增加新的虚拟主机
在实际的开发测试中,有时候我们需要在本地配置很多个站点,比如:8080端口指向项目1,8081端口指向项目2。这时候我们可以通过使用以下方式来配置apache的httpd.conf文件。
情况一:需要添加的虚拟主机是配置文件中Directory中指定目录的子目录时。
<Directory "L:\Projects"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
Listen 8081 <VirtualHost *:8081> DocumentRoot L:\Projects\web1 </VirtualHost>
情况二:新添加的虚拟主机与默认的Directory中的目录不同时,我们需要先添加一个新的Directory,然后再增加VirtaulHost。
<Directory "D:/Codes"> Options Indexes FollowSymLinks AllowOverride None Order deny,allow Allow from all </Directory> Listen 8080 <VirtualHost *:8080> DocumentRoot D:\Codes </VirtualHost>
如果不在这里指定新的Directory,会提示无权限访问。