MAMP:如何运行Vhost站点和默认站点

So I enabled a vHost in my httpd.conf by enabling Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and in /etc/host I made entry as:

127.0.0.1 mydomain.com

Now even if I try localhost it goes to mydomain.com

In the MAMP Environment, Virtual Hosts are quite easy to implement. However, in your case you might have probably forgotten to add some entries to /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf. Adding entries to the /etc/host alone is not enough and again (in your case) the line: 127.0.0.1 mydomain.com says that all requests (no matter which) should be forwarded to mydomain.com

Now to make this work the way you had expected, open up /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf and add the following Entries:

        # THIS ENSURES THAT localhost IS STILL INTACT...
        <VirtualHost *:80>
            DocumentRoot /Applications/MAMP/htdocs
            ServerName localhost
        </VirtualHost>    

        # THIS LOADS UP THE mydomain.com VIRTUAL HOST
        <VirtualHost *:80>
            ServerAdmin webmaster@mydomain.com
            DocumentRoot "/Applications/MAMP/htdocs/mydomain"
            ServerName mydomain.com
            ServerAlias www.mydomain.com
            ErrorLog "logs/mydomain-error_log"
            CustomLog "logs/mydomain.com-access_log" common
        </VirtualHost>

The Lines above ensures that when you call mydomain.com, the appropriate Virtual Host is loaded in this case the index File under /Applications/MAMP/htdocs/mydomain but still, calling localhost would load the default MAMP Welcome Page (except when configured otherwise).

IMPORTANT

Make sure (also) that in your hosts File, the entry: 127.0.0.1 localhost is there (preferably, as the first Entry). In other words, your hosts File is expected to look something like this:

    ##
    # 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       mydomain.com
    255.255.255.255 broadcasthost
    ::1             localhost