在 Apache、ping 等工作时无法通过 cURL 连接到本地虚拟主机(错误 7)

Cannot connect to local vhosts via cURL (error 7) while Apache, ping, etc. work

我急需帮助。我已经花了将近一天的时间试图弄清楚为什么在我重新启动 macOS High Sierra 后 cURL 突然在本地虚拟主机上抛出 curl: (7) Failed to connect to magento.localhost port 80: Connection refused

我的设置之前没有问题 – ping 仍然有效,在浏览器中打开域也按预期工作。怎么回事??

ping magento.localhost

PING magento.localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.034 ms

主机magento.localhost

magento.localhost has address 127.0.0.1
magento.localhost has IPv6 address ::1

scutil -r magento.localhost

Reachable

apachectl configtest

Syntax OK

netstat -a | grep HTTP | grep LISTEN

tcp46 0 0 *.http . LISTEN

curl -v magento.localhost

Rebuilt URL to: magento.localhost/
Trying 127.0.0.1...
TCP_NODELAY set
Connection failed
connect to 127.0.0.1 port 80 failed: Connection refused
Failed to connect to magento.localhost port 80: Connection refused
Closing connection 0
curl: (7) Failed to connect to magento.localhost port 80: Connection refused

have tried every suggestions I found! - 非常感谢您的帮助!

Nic3500, you saved my life! After your 我发现我的虚拟主机产生的结果与本地主机本身不同。

telnet magento.localhost80

Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection
refused telnet: Unable to connect to remote host

远程登录本地主机 80

Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

所以我将 /usr/local/etc/dnsmasq.conf 更改为 address=/localhost/::1 并且 /private/etc/resolver/localhostnameserver ::1,现在 cURL 与其他一切一起工作。

非常感谢!