无法通过MAMP设置多个虚拟主机

时间:2017-06-16 18:49:22

标签: mamp virtualhost

我正在尝试为我的MAMP htdocs文件夹中的项目设置虚拟主机。但似乎我无法创造多个。例如,如果我在httpd-vhosts.conf文件中有这个:

<VirtualHost *:80>
  DocumentRoot "/Applications/MAMP/htdocs/first-project/public"
  ServerName first-project.dev
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/Applications/MAMP/htdocs/second-project/public"
  ServerName second-project.dev
</VirtualHost>

然后我将浏览器指向second-project.dev,它将显示first-project.dev的内容。如果我删除了第一个项目的v-host条目,那么我可以毫无问题地查看second-project.dev。由于某种原因,它不喜欢我有多个条目。

我的/ etc / hosts文件中有以下内容:

##
# 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
127.0.0.1   first-project.dev
127.0.0.1   second-project.dev

255.255.255.255 broadcasthost
::1             localhost

我错过了什么吗?也许是httpd.conf中的一个设置?

1 个答案:

答案 0 :(得分:1)

我找到了自己问题的答案。在建立多个虚拟主机条目时,您需要在条目之前使用以下行:

NameVirtualHost *:80

此外,您需要建立所需的目录来替换默认的localhost:

<VirtualHost *:80>
      DocumentRoot "/Applications/MAMP/htdocs/"
      ServerName localhost
</VirtualHost>

我的完整httpd-vhosts.conf文件:

NameVirtualHost *:80

<VirtualHost *:80>
      DocumentRoot "/Applications/MAMP/htdocs/"
      ServerName localhost
</VirtualHost>

<VirtualHost *:80>
      DocumentRoot "/Applications/MAMP/htdocs/sampleapp/public/"
      ServerName sampleapp.dev
</VirtualHost>

<VirtualHost *:80>
      DocumentRoot "/Applications/MAMP/htdocs/simplewebsite/public/"
      ServerName simplewebsite.dev
</VirtualHost>