MAMP VirtualHost chooses wrong directory

浪尽此生 提交于 2020-06-01 07:21:25

问题


I got a problem with MAMP.

I added in the httpd-vhosts.conf these lines of code:

<VirtualHost *:80>
    ServerName "site1.dev"
    DocumentRoot "/Users/kevingorjan/site1/public_html/"

    <Directory "/Users/kevingorjan/site1/public_html/">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerName "site2.dev"
    DocumentRoot "/Users/kevingorjan/site2/public_html/"

    <Directory "/Users/kevingorjan/site2/public_html/">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

And I updated my /etc/hosts

127.0.0.1 site1.dev
127.0.0.1 site2.dev

When I surf to site1.dev. Everything goes as expected. The servers loads the correct content specified to this URL. But when I surf to site2.dev, I'll receive the same content from site1.dev. Is there something that I miss or do I have to change something else in the configuration?

Thanks in advance

* SOLUTION *

Sorry, I found the problem. I'm working on my Mac and I have apache running while my MAMP is also running. I removed the apache on my machine and now everything is working fine. Thanks


回答1:


Sorry, I found the problem.

I'm working on my Mac and I have apache running while my MAMP is also running. I removed the apache on my machine and now everything is working fine.

Thanks




回答2:


You're doing it wrong ;) Your virtualhosts file should look more like this :

NameVirtualHost *:80 

<Directory "D:/projects/">
  Require local
</Directory> 

<VirtualHost *:80>
 DocumentRoot "D:/projects/project_1/public_html"
 ServerName project_1.dev
</VirtualHost>

<VirtualHost *:80>
 DocumentRoot "D:/projects/project_2/public_html"
 ServerName project_2.dev
</VirtualHost>

IF you are using apache < 2.4 than replace :

Require local

with :

Order allow,deny
Allow from all



回答3:


In your hosts file make sure you supply the ipv6 address for your site along with the ipv4

127.0.0.1 site1.dev
127.0.0.1 site2.dev
::1 site1.dev
::1 site2.dev

You might not need the directory tag in your vhosts.conf file

Also make sure that MAMP is using MySQL and Apache default ports and not MAMP defaults in the preferences pane.



来源:https://stackoverflow.com/questions/17322422/mamp-virtualhost-chooses-wrong-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!