当我们在开发项目或者在学习时,总会建立多个项目。这样在apache中默认的工作目录只有在htdocs目录下。所以我们必须建立虚拟主机,让我们的单台计算机可以当多个服务器来使用。这里我们就需要配置虚拟主机
# Virtual hosts #Include conf/extra/httpd-vhosts.conf我们仅需要去掉Include前面的“#”即可达到目的,变成如下
# Virtual hosts Include conf/extra/httpd-vhosts.conf
# # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> ServerName www.cyxlgzs.com DirectoryIndex index.php DocumentRoot "F:/MyWorkSpace/project/php/cyxlgzs" <Directory "F:/MyWorkSpace/project/php/cyxlgzs"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName www.first_php.com DirectoryIndex index.php DocumentRoot "F:/MyWorkSpace/project/php/first_php" <Directory "F:/MyWorkSpace/project/php/first_php"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
NameVirtualHost *:80
Listen 80
127.0.0.1 www.cyxlgzs.com 127.0.0.1 www.first_php.com