【问题标题】:2 Virtual Hosts on MacMac 上的 2 个虚拟主机
【发布时间】:2014-11-19 06:41:41
【问题描述】:

大家好,我有两个不同的站点,我想要两个不同的主机: 电影.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的内容,为什么?

【问题讨论】:

  • "如果我去music.local,我的浏览器会加载music.local的内容,为什么?"这不是你想要的吗?还是你说错了?无论如何,请记住在编辑任何配置文件后重新启动 httpd。
  • 对不起,我已经编辑了,是的,我做到了
  • 如果您经常这样做,您可能希望使用Localghost 来更轻松地编辑该文件。您也可以使用xip.io 进行映射,例如:movies.127.0.0.1.xip.io 将解析为127.0.0.1

标签: mysql macos virtual host


【解决方案1】:

如果我访问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

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2020-09-11
    • 2012-09-20
    • 2012-02-16
    • 2018-11-08
    • 2020-12-17
    • 2013-02-18
    • 2017-10-10
    相关资源
    最近更新 更多