开发者

Having trouble with multiple hosts on Apache Snow Leopard

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.

Here's what I've tried:

In my etc/hosts file I've set added these entries:

127.0.0.1    testsite1.localdev.com
127.0.0.1    testsite2.localdev.com

Then, in apache2/httpd.conf I have added these entries:

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite1
   ServerName testsite1.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite1">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite2
   Ser开发者_开发问答verName testsite2.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite2">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.

I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.

I am being sure to reboot apache after each change.

Thanks for any help!

Gary


  • in /etc/apache2/httpd.conf uncomment the vhost file like:

    # Virtual hosts
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  • in /private/etc/apache2/extra/httpd-vhosts.conf use...

    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80
    
    <VirtualHost *:80>
        DocumentRoot "/Library/WebServer/Documents"
        ServerName localhost
    </VirtualHost>
    
    # local test site
    <VirtualHost *:80> 
      <Directory /Users/<youruser>/Sites/test>
        AllowOverride All 
      </Directory> 
      DocumentRoot "/Users/<youruser>/Sites/test"
      ServerName test.local
    </VirtualHost>
    
  • Be sure that your and Sites folders have permissions of 755

and be sure that you add to your /etc/hosts file...

# test
127.0.0.1   test.local
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜