【问题标题】:Localhost is not working本地主机不工作
【发布时间】:2014-07-25 22:37:13
【问题描述】:

我花了一天时间解决这个问题,但我无法解决它。

每次我尝试访问我的本地主机或输入 127.0.0.1 时,我使用的浏览器都会返回一个错误,例如:“Firefox 无法在 www.localhost.com 找到服务器地址。”(i'我是法语,我翻译了这个问题)。

在 Google Chrome 和 127.0.0.1 中也会出现同样的问题。我尝试了 XAMPP 和 WAMP,仍然没有。我的 Apache httpd.conf 看起来不错,我尝试更改端口(8080、81、8800)。它仍然无法正常工作。我的 Skype 没有打开下 VMware Workstation。没有程序阻止对端口 80 或 443 的访问。

我已经用 localhost 进行了 ping 测试,一切正常,但我无法访问 WAMP 或 XAMP 的索引页面。

奇怪的是我可以访问 localhost/phpmyadmin 和其他类似的页面。

我认为我的问题出在 Windows 的 hosts 文件中,但对我来说似乎没问题:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

127.0.0.1 localhost

::1 localhost

我为什么要考虑 hosts 文件?因为我在 XAMPP 和 WAMP 中的虚拟主机不工作。也许我错了,但这个问题让我发疯!

感谢您的帮助

【问题讨论】:

  • 主机文件只会将名称映射到 IP,而不是相反。

标签: apache xampp localhost wamp hosts


【解决方案1】:

奇怪的是我可以访问 localhost/phpmyadmin 和其他 像这样的页面。

听起来你的主机文件很好。有一些东西阻止 Apache 启动并绑定到您的端口。

我对Windows不太熟悉,但是from the documentation

Apache 启动期间的任何错误都会记录到 Windows 事件日志中 在 Windows NT 上运行时。这种机制充当了那些 Apache 尚未准备好使用 error.log 文件的情况。 您可以使用事件查看 Windows 应用程序事件日志 查看器,例如开始——设置——控制面板——管理工具—— 事件查看器。

看看是什么阻止了 Apache 启动。

【讨论】:

  • 我的 Apache 正在运行,我已经重新安装了几次 Xampp。如果我粘贴 error.log 可能会有所帮助?
【解决方案2】:

如果您已经定义了虚拟主机,这是一个非常好的主意,那么您需要在 HOSTS 文件中定义虚拟主机名称。

例如hosts文件:

127.0.0.1 localhost
::1 localhost

127.0.0.1 vhost1.dev
::1 vhost1.dev

127.0.0.1 vhost2.dev
::1 vhost2.dev

否则 windows 无法知道在哪里寻找它们。

localhost 不工作的另一种可能性是 HOSTS 文件损坏。尝试删除它并使用不是记事本的编辑器重新创建它。

此外,当您更改 HOSTS 文件时,您需要通过重新启动来重新启动 dmscache 服务“DNS 客户端”,或者最好仍然使用“以管理员身份运行”运行命令窗口并执行此操作

net stop dnscache
net start dnscache

激活主机文件中的新条目。

【讨论】:

  • 好的,我按照你说的做了,在我决定在 vhosts.conf 中为 localhost 创建一个虚拟主机之后,现在它可以工作了。我不知道它是命令行还是虚拟主机,但现在,它正在工作。谢谢!
【解决方案3】:

如果它会帮助你,我现在不知道,这是我重新启动 Apache 时在日志中得到的内容

[Thu Jun 05 15:41:13.480163 2014] [mpm_winnt:notice] [pid 9984:tid 392] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Thu Jun 05 15:41:15.481278 2014] [mpm_winnt:notice] [pid 6728:tid 268] AH00364: Child: All worker threads have exited.
[Thu Jun 05 15:41:15.504279 2014] [mpm_winnt:notice] [pid 9984:tid 392] AH00430: Parent: Child process 6728 exited successfully.
[Thu Jun 05 15:41:20.536567 2014] [ssl:warn] [pid 9648:tid 392] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Thu Jun 05 15:41:20.735578 2014] [ssl:warn] [pid 9648:tid 392] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Thu Jun 05 15:41:20.757580 2014] [mpm_winnt:notice] [pid 9648:tid 392] AH00455: Apache/2.4.9 (Win32) OpenSSL/1.0.1g PHP/5.5.11 configured -- resuming normal operations
[Thu Jun 05 15:41:20.757580 2014] [mpm_winnt:notice] [pid 9648:tid 392] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:13:13
[Thu Jun 05 15:41:20.757580 2014] [core:notice] [pid 9648:tid 392] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Thu Jun 05 15:41:20.758580 2014] [mpm_winnt:notice] [pid 9648:tid 392] AH00418: Parent: Created child process 3700
[Thu Jun 05 15:41:21.108600 2014] [ssl:warn] [pid 3700:tid 268] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Thu Jun 05 15:41:21.274609 2014] [ssl:warn] [pid 3700:tid 268] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Thu Jun 05 15:41:21.296610 2014] [mpm_winnt:notice] [pid 3700:tid 268] AH00354: Child: Starting 150 worker threads.

昨天,我设法摆脱了 [ssl:warn] [pid 3700:tid 268] AH01909,但这不是问题。

在我的 Windows 事件查看器中,没有任何变化,在重启的同时没有任何报告。

注意:我已经卸载了我当前的防病毒软件(我现在不推荐使用它)并且我的 Windows 防火墙似乎没有阻止与 localhost 的连接。

【讨论】:

    【解决方案4】:

    好的,我已经完成了 RiggsFolly 告诉我的事情。我删除了我的主机文件并创建了一个新文件。我重新启动了 dmscache 服务。之后,我决定为我的本地主机创建一个虚拟主机。在我的 httpd.conf 中,我检查了虚拟主机是否包含

    Include conf/extra/httpd-vhosts.conf
    

    在我的 httpd-vhosts.conf 中我写道:

    <Directory "/xampp/htdocs">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    
    <VirtualHost *:80>
        ServerName localhost
        ServerAdmin webmaster@das.com
        DocumentRoot /xampp/htdocs/
        <Directory "/xampp/htdocs/">
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    

    现在一切似乎都正常了,我可以在我的主机文件中创建其他具有自定义名称的虚拟主机。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-15
      • 2018-06-27
      • 2017-11-06
      • 2015-10-03
      • 2013-05-31
      • 2017-07-18
      • 2015-11-30
      相关资源
      最近更新 更多