apache 什么都试过了;“localhost”仍然无法解析

qkf9rpyu  于 2023-03-03  发布在  Apache
关注(0)|答案(1)|浏览(200)

我有一个运行约塞米蒂(10.10.3)的iMac,我在上面安装了MAMP,Apache和MySQL启动正常,但我无法访问任何页面,因为localhost没有解析。
我已经尝试了一切,执行我找到的每一个终端命令,刷新任何可刷新的东西,修改/删除/添加回我的主机文件中所有可能的组合,重新启动,修改Mac OS和MAMP的httpd.conf文件上的ServerName变量,没有任何修复它。
现在,有趣的部分是127.0.0.1**(Mac OS Apache为:80或WAMP为:8888) 解析,我得到著名的“它工作了!”,如果我尝试my-macs-name.local**(Mac OS Apache为:80或WAMP为:8888),也会发生这种情况。
我的主机文件如下所示:

##
# 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

Mac OS Apache httpd.conf文件ServerName部分如下所示:

# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80

WAMP的是这样的:

# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:8888

Safari(或任何浏览器)返回:

Ping本地主机返回:

ping: cannot resolve localhost: Unknown host

我已经通过每一个堆栈溢出,博客,互联网教程,谷歌已经指出我,但仍然不能解决这个问题。任何帮助将不胜感激。

1sbrub3j

1sbrub3j1#

7年后,我遇到了这个问题。原来它不能为我解析终端中的::1。它试图将localhost解析为该地址,而不是127.0.0.1(也指定了,我猜IPv6优先)。从/etc/hosts中删除::1为我解决了这个问题,所以看起来IPv6地址有一些问题。

相关问题