[英]MAMP: How can I run both Vhost sites and default sites
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: 因此,我通过启用
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
在httpd.conf中启用了vHost,在/etc/host
我输入为:
127.0.0.1 mydomain.com
Now even if I try localhost
it goes to mydomain.com
现在,即使我尝试使用
localhost
它也会进入mydomain.com
In the MAMP Environment, Virtual Hosts are quite easy to implement. 在MAMP环境中,虚拟主机非常容易实现。 However, in your case you might have probably forgotten to add some entries to
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
. 但是,在您的情况下,您可能忘记了向
/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 仅将条目添加到
/etc/host
是不够的,并且在您的情况下,这一次又一次: 127.0.0.1 mydomain.com
表示所有请求(无论哪个请求)都应转发到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: 现在,按照您期望的方式进行此工作,打开
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
并添加以下条目:
# 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). 上面的代码行确保在调用
mydomain.com
,在这种情况下,将在/Applications/MAMP/htdocs/mydomain
下加载适当的虚拟主机索引文件,但仍然,调用localhost
将加载默认的MAMP Welcome Page(除非另有配置) )。
IMPORTANT 重要
Make sure (also) that in your hosts
File, the entry: 127.0.0.1 localhost
is there (preferably, as the first Entry). 确保(也)在
hosts
文件中,条目: 127.0.0.1 localhost
存在(最好是第一个条目)。 In other words, your hosts
File is expected to look something like this: 换句话说,您的
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 mydomain.com
255.255.255.255 broadcasthost
::1 localhost
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.