前提在MAC上安裝了MAMP
進入/Applications/MAMP/conf/apache/extra/目錄
找到httpd-vhosts.conf文件 打開,
<VirtualHost *:80>
DocumentRoot "項目目錄"
ServerName localhost
ServerAlias localhost
<Directory "項目目錄">
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
進入 /private/etc/ 找到hosts文件。copy一份出來 打開,定一個虛擬域名(localhost)和本地ip127.0.0.1對應,覆蓋之前文件
這樣我們就可以通過localhost來了。
但是在我機子上配置多個虛擬主機的時候遇到個問題,在這個項目目錄的子目錄里面配置另一個虛擬域名(api.leave.com)和本地ip127.0.0.1對應。運行的時候總是提示404 Not Found !The requested URL /xxx/xxxxx was not found on this server.
2017-04-14 補寫
今天上stackoverflow去找了下出現Not Found大家是怎么說的,然后看到有人說是下面這樣寫,我就試了下。咦,配置的虛擬域名都可以用了。。但自己還是一臉懵逼,不知道為什么會出現這樣的情況....
<Directory "/Users/Victor/Desktop/Works/Project/“>
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/Users/Victor/Desktop/Works/Project"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/Victor/Desktop/Works/Project/xxx"
ServerName api.xxx.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/Victor/Desktop/Works/Project/xxx1/public"
ServerName api.xxx1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Users/Victor/Desktop/Works/Project/xxx2/public"
ServerName api.xxx2.com
</VirtualHost>