我正在尝试在我的本地主机上创build子域名,并且离开我的领域…我在Mac OS X上运行MAMP,并且认为/必须执行以下操作:
(假设我想创buildme.localhost.com和you.localhost.com)
(1)编辑/ private / etc / hosts
现在看起来像这样:
127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
所以,我只是做到这一点:
127.0.0.1 localhost 127.0.0.1 me.localhost.com 127.0.0.1 you.localhost.com 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
(2)我假设我根本不需要混淆DNS,因为它是本地的? 那么,hosts文件应该足够了?
(3)然后,我需要编辑我的httpd.conf文件来包含虚拟主机? 我尝试过这个,但是不是在挑选它
NameVirtualHost * <VirtualHost *> DocumentRoot "/Applications/MAMP/htdocs" ServerName localhost </VirtualHost> <VirtualHost *> DocumentRoot "/Applications/MAMP/htdocs/me.localhost.com" ServerName me.localhost.com </VirtualHost> <VirtualHost *> DocumentRoot "/Applications/MAMP/htdocs/you.localhost.com" ServerName you.localhost.com </VirtualHost>
不知道,如果我在这里基地的方式…帮助是非常感谢!
对于本地名称parsing:
你需要localhost.com吗? 在我的环境中:
$ vi /etc/hosts 127.0.0.1 localhost 127.0.0.1 box1 box2 box3 $ ping box1
返回“127.0.0.1”就好了。
在浏览器中,我也可以parsinghttp:// box1 , http:// box2等等。
在10.5,10.6以上,我至less可以确认OSX不应该覆盖你的/ etc / hosts,这是上一个答案的问题。
对于Apache,对于每个新的虚拟主机,添加:
<VirtualHost *:80> ServerName box1 DocumentRoot /full/path/to/documentroot/ ...[etc] </VirtualHost>
由于您的浏览器将正确parsing为'box1'为127.0.0.1,您的请求将被路由到本地框,在那里apache将读取标题,并看到它是为'box1',并将使用相应的虚拟主机。
或者,你也可以使用其中一个(许多?)工具来为你自动化,比如(我不隶属于这个,只是在试图find我想到的另一个例子的时候快速search一下: http:// clickontyler。 com / virtualhostx / )
请注意,127.0.0.1的所有别名应该在一行中指定,否则会得到奇怪的结果(至less在Linux中)。
127.0.0.1 localhost me.localhost.com you.localhost.com
VirtualHost
获取要定义的虚拟主机的名称。 <VirtualHost *>
定义了全部默认。 所以,应该是
<VirtualHost me.localhost.com>
(我希望你明白, me.localhost.com
是违反了TwoCows命名空间,与me.localhost
完全不同)。
我不太确定OS X会覆盖/etc/hosts
频率。 可能需要使用Open Directory,但正如我刚刚意识到的那样, man DirectoryService) in Snow Leopard points to a non-existing utility (
/Applications/Utilities/Directory Utility.app
). Ie, you'd need to use dscl
and, probably, go to /Local/Default/Hosts中( man DirectoryService) in Snow Leopard points to a non-existing utility (
/Applications/Utilities/Directory Utility.app
). Ie, you'd need to use dscl
and, probably, go to /Local/Default/Hosts的手册页man DirectoryService) in Snow Leopard points to a non-existing utility (
/Applications/Utilities/Directory Utility.app
). Ie, you'd need to use dscl
and, probably, go to /Local/Default/Hosts man DirectoryService) in Snow Leopard points to a non-existing utility (
/Applications/Utilities/Directory Utility.app
). Ie, you'd need to use dscl
and, probably, go to /Local/Default/Hosts并在其中添加条目。