mac hosts文件 - 只有主页URL工作

时间:2013-10-25 19:02:07

标签: macos local host

我在我的Mac上设置了我的主机文件

127.0.0.1       my.localsite.com
127.0.0.1       my2.localsite.com
##
# 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
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

127.0.0.1       more.localsite.com
127.0.0.1       more2.localsite.com

当我转到http://my.localsite.com:8080时,我正在处理的网站的主页显示正确。当我转到该网站的另一个链接时,例如my.localsite.com:8080/page1或my.localsite.com:8080/page2,我的浏览器告诉我该网站无法找到。我已将my和my2.localsite.com添加到hosts文件的顶部,这没有什么区别。

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试:

127.0.0.1       localhost my.localsite.com my2.localsite.com more.localsite.com more2.localsite.com
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

如果hosts文件不是问题,看起来如此(请参阅下面的评论),那么它可能与Web服务器的虚拟主机配置有关。你没有提到你正在使用什么服务器,所以我不能给出具体的答案。我们以Apache为例。 它可以是configured to serve different sites based on the hostname

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

因此,结论是:检查您的Web服务器虚拟主机配置。