Port 80: connection refused. How to fix on Mac OSX? [duplicate]

I've noticed some issues with Apache virtual hosts on two Macs that otherwise have the same kind of set up (in terms of httpd.conf, vhosts, hosts etc.) On one Mac, virtual hosts are served without a glitch, on another, I am getting connection refused on port 80.

This doesn't seem to be a problem with Apache configuration, I think, but something to do with ports.

Namely, the machine that fails to serve the virtual host test.dev on 80 shows me this on port scan:

Сканирование портов выполняется…

Port Scanning host: 127.0.0.1

     Open TCP Port:     88          kerberos
     Open TCP Port:     445         microsoft-ds
     Open TCP Port:     548         afpovertcp
     Open TCP Port:     631         ipp
Сканирование портов завершено…

The machine that does serve test.dev show this:

Port Scanning host: 127.0.0.1

     Open TCP Port:     22          ssh
     Open TCP Port:     53          domain
     Open TCP Port:     80          http
     Open TCP Port:     88          kerberos
     Open TCP Port:     445         microsoft-ds
     Open TCP Port:     548         afpovertcp
     Open TCP Port:     631         ipp
Сканирование портов завершено…

So on the "good" machine, port 80 is listed, on the "bad" machine it isn't.

On both machines I have apache listening to *:80 etc, properly set up vhosts, an appropriate entry in the hosts file etc. Both Macs are running El Capitan, are on the same network etc.

And while on the good mac, test.dev is served, on the bad mac, I get this:

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

I'm at a bit of a loss, because I don't know how to fix this. Why is port 80 not showing up in the port scan of the bad Mac (using the Network Utility app), yet sudo lsof -i -P | grep -i "80"gives me:

httpd     4482           root    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)
httpd     4484         daemon    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)
httpd     4485         daemon    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)
httpd     4486         daemon    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)
httpd     4487         daemon    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)
httpd     4488         daemon    5u  IPv6 0xfe89d5ee2c7da24b      0t0  TCP *:80 (LISTEN)

Many thanks in advance.

All best, Tench

Edit: I was asked to justify why this is not a duplicate question to the more general question about connection refused. It isn't because my question was specific to Mac OSX and the solution that worked for me (see below) required editing pf.conf and using pfctl which is not mentioned in the supposed duplicate question at all.


Solution 1:

To make sure port 80 is open for TCP on all interfaces, I added

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, the port shows up as open in port scan, and my virtual hosts are served as they should.