【问题标题】:mac hosts file - only home URL worksmac 主机文件 - 只有主页 URL 有效
【发布时间】:2013-11-05 00:38:28
【问题描述】:

我在我的 Mac 上设置了我的 hosts 文件

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 文件的顶部,但这并没有什么不同。

有什么建议吗?

谢谢!

【问题讨论】:

    标签: macos local host


    【解决方案1】:

    试试:

    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 文件没有问题并且看起来确实如此(请参阅下面的 cmets),那么它可能与 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>
    

    所以,结论是:检查您的网络服务器虚拟主机配置。

    【讨论】:

    • 我尝试这样做,最初认为它有效,但意识到我使用的本地站点中的一个设置不正确。我仍然只能让主页工作。所有其他网站链接都显示为找不到页面。
    • 好的,所以hosts 没有问题。也许是虚拟主机配置 - 请参阅上面的更新答案。
    猜你喜欢
    • 2012-09-19
    • 1970-01-01
    • 2017-06-28
    • 2021-09-24
    • 2015-12-24
    • 2022-01-11
    • 2019-12-25
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多