简体   繁体   English

MAMP:如何同时运行Vhost网站和默认网站

[英]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.

相关问题 如何从一个站点向另一个站点发送日期? - How can I send a date from one site to other sites? 我如何通过PHP(反向IP)知道IP是否托管站点 - How i can know if the IP host a sites or not by PHP (Reverse IP) 我如何申请或使用 selenium 测试到 php 站点 - How can i apply or use selenium testing to php sites 如何在wordpress多站点设置中为新站点自定义默认设置? - How do I customize default settings for new sites on wordpress multisite setup? 如果我从 MAMP 安装它,我如何运行 mysql - how can I run mysql if I installed it from MAMP 如何在PHP中使用cURL抓取的网站上正确跟踪所有重定向? - How can I properly follow all redirects on sites I am trying to scrape with cURL in PHP? 我如何在PHP和Drupal的两个不同站点之间共享一个会话 - How can i share one session across two different sites in PHP and Drupal 如何使用git自动更新生产中的所有Laravel网站? - How can I use git to automatically keep all Laravel sites in production updated? 如何设置客户可以嵌入其网站的搜索小部件? - How should I set up a search widget that customers can embed on their sites? 如何防止其他网站链接到我的 javascript 文件? - How can I prevent other sites from linking to my javascript files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM