2台Mac上的虚拟主机

时间:2014-09-24 16:59:16

标签: mysql macos virtual host

大家好,我有两个不同的网站,我想要两个不同的主机: movie.local music.local

这些是我的文件:

#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost
127.0.0.1   movie.local
127.0.0.1   music.local

#
# 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 movie.local

    ServerAlias www.movie.local

    DocumentRoot "/Users/Me/Sites/movie"

    ErrorLog "/private/var/log/apache2/site-error_log"

    CustomLog "/private/var/log/apache2/site-access_log" common

    ServerAdmin neilgee@coolestguidesontheplanet.com

        <Directory "/Users/Me/Sites/movie">

            Options Indexes FollowSymLinks

            AllowOverride All

            Order allow,deny

            Allow from all

        </Directory>

</VirtualHost>

<VirtualHost *:80>

         ServerName music.local

        ServerAlias www.music.local
        DocumentRoot "/Users/Me/Sites/music"

    ErrorLog "/private/var/log/apache2/site-error_log"

   CustomLog "/private/var/log/apache2/site-access_log" common

    ServerAdmin neilgee@coolestguidesontheplanet.com

        <Directory "/Users/Me/Sites/music">

            Options Indexes FollowSymLinks MultiViews

            AllowOverride All

            Order allow,deny

            Allow from all

        </Directory>

</VirtualHost>

但现在如果我去movie.local那没关系,但如果我去music.local,我的浏览器会加载movie.local的内容,为什么?

1 个答案:

答案 0 :(得分:0)

如果我去music.local,我的浏览器会加载movie.local的内容,为什么? 您可以像这样在本地主机上创建一个子域。

首先创建一个虚拟主机:

<VirtualHost *:80>
ServerName music.localhost
DocumentRoot "C:/Users/Me/Sites/music"
 <Directory "C:/Users/Me/Sites/music">
/....../
/....../
</Directory>
</VirtualHost>

And in your hosts file add this line:
127.0.0.1      music.localhost