在Mac OS X Mavericks上访问localhost时出现问题……直到我今天重新启动后,它工作正常


16

我对自己遇到的问题感到困惑,非常感谢您解决该问题。

我有一台运行Mac OS X Mavericks 10.9.2的iMac

我已经设置了我的apache服务来从服务器根目录/ Volume / sites /

我使用的是动态虚拟主机,因此只需添加带有* .dev后缀的目录,它便会成为虚拟主机。

我的主机文件非常基本:

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

我的httpd-vhosts.conf文件如下:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

#allow access to the Hosts directory where your sites are
<Directory "/Volumes/sites">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    #you could configure the following to only allow access from localhost
    Order allow,deny
    Allow from all
</Directory>

#get the server name from the Host: header
UseCanonicalName Off
VirtualDocumentRoot /Volumes/sites/%0/

这一切都奏效。而且我还没有更改httpd.conf文件中的任何内容。

但是我无法加载本地主机

我也无法加载127.0.0.1

我运行命令sudo lsof -i :80 | egrep "PID|LISTEN"以查看是否有任何PID在端口80上监听。结果为空。

我尝试重新启动apache并也停止然后使用以下命令启动apache

sudo apachectl stop sudo apachectl start

sudo apachectl restart

没用。

我通过发出命令来检查apache是​​否正在运行 httpd -v

回报是:

Server version: Apache/2.2.26 (Unix)
Server built:   Dec 10 2013 22:09:38

我尝试通过命令行连接到localhost和127.0.0.1,结果如下:

alisamii at alisamii in ~
$ telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host
alisamii at alisamii in ~
$ telnet 127.0.0.1 80
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
alisamii at alisamii in ~
$ lynx http://localhost

Looking up localhost
Making HTTP connection to localhost
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/
alisamii at alisamii in ~
$ lynx http://127.0.0.1

Looking up 127.0.0.1
Making HTTP connection to 127.0.0.1
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://127.0.0.1/
alisamii at alisamii in ~

请帮忙。


您对这个问题做了什么,因为我在这里遇到了完全相同的事情:(
Pmpr

Answers:


38

有同样的问题。我删除了项目的一个文件夹,该文件夹已损坏。在这种情况下,应该从httpd-vhosts.conf和httpd.conf中删除站点的配置。

尝试 ping 127.0.0.1

apachectl configtest 可以帮助您发现问题。


7
绝对正确,apachectl configtest需要您的第一次尝试!谢谢。
卢卡斯·塞拉芬2015年

警告:DocumentRoot [/ Users / me / blah / blah]不存在,您可以使用sudo cd / && grep -rn "/Users/me/blah/blah" *
Shanimal

4

问题可能是主机文件可能已从原始ASCII编码中损坏。我清除了所有空格并在其中放了标签,然后运行sudo killall -HUP mDNSResponder(您可以执行此操作,而不必重新启动),然后运行了。


1
是的,/etc/hosts已经损坏-重复的行,一些空间那里曾经是标签......现在要弄清楚这是怎么发生....
LeeGee

3

就我而言,问题在于文件夹/ p​​rivate / var / log / apache2 /由于未知原因而丢失。用

sudo mkdir /private/var/log/apache2

然后重新启动apache

sudo apachectl restart

搞定了!


2

拒绝连接最常见的原因是服务器没有监听端口。

语法错误或常规配置文件错误将在启动时终止apache(通常不向错误日志或终端报告)。

尝试运行sudo apachectl configtest,看看它是否输出任何错误消息。


-1

它是Mac专用的。首先,您必须启用Web共享。对于Maveric,可以按照本教程中的说明进行操作。https://www.youtube.com/watch?v=TgiZiTU9JVY 其次,为Mac如果通过pfctl的过滤(即人pfctl的)在MAVERIC和IPFW(人IPFW)为老年版的Mac OS,如果你需要超过端口的流量80


关于“与众不同”的答案不仅需要链接。可以包含链接,但请在答案中进行总结或摘录。这个想法是使答案独立存在。
nohillside

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.