PHP-MAC上通过MAMP配置虚拟主机

2017-03-16  本文已影响514人  南方小金豆

前提在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>

上一篇下一篇

猜你喜欢

热点阅读