10

I have Apache 2.4 running on Mac OS X. apachectl configtest give me: Syntax OK.

I have two virtual hosts set up, one called localhost, one called 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 just works:

↪ 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

whereas test.dev doesn't:

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

My hosts file has an entry for test.dev, which is why I can ping test.dev and hear back from 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

I've spent hours looking at this, but I still don't understand how it is possible to ping test.dev but still get connection refused. Apache is listening on port 80, and I am not getting a page forbidden kind of error. There is nothing in Apache logs for test.dev, because the request for test.dev never makes it to Apache.

I am missing a crucial element of the puzzle — and I hope somebody will be able to point me in the right direction.

Many thanks in advance.

Edit: As I said, Apache is listening on 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)

Additional info

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 is in /etc/hosts and Listen *:80 is in apache's conf.

Tench
  • 361

3 Answers3

8

Check you httpd.conf to see if you have the following:

Listen 127.0.0.1:80

You have to replace it with:

Listen *:80

By doing this, Apache will bind to all of the computer's interfaces, not just the loopback interface.

Don't forget to restart Apache after editing httpd.conf.

4

Even though Apache was listening to port 80, this port was refusing connection. In the end this is what worked for me:

I made sure port 80 was open for TCP on all interfaces, which on OSX you do by adding

pass in proto tcp from any to any port 80

to /etc/pf.conf. Reloading pfctl didn't quite do the trick, but a reboot did. Now all my virtual hosts are accessible. And the world is in order again.

Tench
  • 361
2

Try to connect test.dev with another available port fot http or https communication. OR stop the previous PID with port ':80' and then run. Check the process ID with -

netstat -ltnp | grep ':80'

kill -9