连接拒绝Apache 2.4虚拟主机

我有Apache 2.4在Mac OS X上运行apachectl configtest给我:语法OK。

我有两个虚拟主机,一个叫做localhost,一个叫做test.dev。

 <VirtualHost *:80> DocumentRoot "/Users/psychomachine/Development/_localhost" ServerName localhost ServerAlias www.localhost <Directory /> Require all granted </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "/Users/psychomachine/Development/test" ServerName test.dev ServerAlias www.test.dev <Directory /> Require all granted </Directory> </VirtualHost> 

localhost只是工作:

 ↪ curl -I -L localhost 15:51:08 HTTP/1.1 200 OK Date: Tue, 08 Dec 2015 14:51:17 GMT Server: Apache/2.4.16 (Unix) Last-Modified: Tue, 08 Dec 2015 08:52:04 GMT ETag: "c-5265f1673f500" Accept-Ranges: bytes Content-Length: 12 Content-Type: text/html 

而test.dev不:

 ↪ curl -I -L test.dev 15:51:01 curl: (7) Failed to connect to test.dev port 80: Connection refused 

我的主机文件有一个test.dev项,这就是为什么我可以ping test.dev并从127.0.0.1听到。

 ↪ ping test.dev 15:53:39 PING test.dev (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.069 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.096 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.111 ms ^C --- test.dev ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 0.069/0.092/0.111/0.017 ms 

我花了几个小时看着这个,但我仍然不明白如何ping test.dev,但仍然被拒绝连接。 Apache正在端口80上侦听,而我没有收到一个禁止的错误页面。 对于test.dev,Apache日志中没有任何内容,因为对test.dev的请求永远不会将其发送给Apache。

我错过了这个难题的一个关键因素 – 我希望有人能够指引我正确的方向。

提前谢谢了。

编辑:正如我所说,Apache正在听80:

 sudo lsof -i ':80' 16:54:46 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 2464 root 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) httpd 2466 daemon 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) httpd 2467 daemon 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) httpd 2468 daemon 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) httpd 2469 daemon 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) httpd 2470 daemon 5u IPv6 0x8883a2a43af0ca7f 0t0 TCP *:http (LISTEN) 

附加信息

 scutil -r test.dev 08:25:59 Reachable telnet test.dev 08:26:17 Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host telnet test.dev 80 08:26:43 Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused telnet: Unable to connect to remote host 

127.0.0.1 test.dev/etc/hostsListen *:80在apache的conf中。

即使Apache正在监听端口80,这个端口也拒绝连接。 最后这是对我有用的:

我确信在所有的接口上,TCP端口都是开放的,在OSX上你可以添加端口

 pass in proto tcp from any to any port 80 

/etc/pf.conf 。 重新加载pfctl并没有完全做到这一点,但重启了。 现在我所有的虚拟主机都可以访问。 世界又有序了。

检查你的httpd.conf ,看看你是否有以下几点:

 Listen 127.0.0.1:80 

您必须将其replace为:

 Listen *:80 

通过这样做,Apache将绑定到所有计算机的接口,而不仅仅是回送接口。

编辑httpd.conf后不要忘记重启Apache。

尝试将test.dev与另一个可用的端口fot http或https通信连接起来。 或者用端口“80”停止先前的PID,然后运行。 检查进程ID –

netstat -ltnp | grep':80'

杀-9