'How to fix `curl: (52) Empty reply from server` response on localhost?

The problem is in my setting, because I am accessing localhost.

When I execute in terminal:

curl http://localhost

The response is:

curl: (52) Empty reply from server

But it should say:

curl: (7) Failed to connect to localhost port 80: Connection refused

UPDATE:

When I execute

curl http://localhost:3000

The response is:

curl: (7) Failed to connect to localhost port 3000: Connection refused

UPDATE(2)

sudo lsof -i :80

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

acwebseca 42015 root 36u IPv4 0x2e120362d0318e9b 0t0 TCP

192.168.0.109:52299->151.101.129.69:http (ESTABLISHED) ...

Do you have any ideas ?



Solution 1:[1]

Check port conflict with following command (Mac) and close applications using same port:

lsof -n -i4TCP:$PORT | grep LISTEN
lsof -n -iTCP:$PORT | grep LISTEN
lsof -n -i:$PORT | grep LISTEN

Substitute $PORT with the port number or a comma-separated list of port numbers.

Prepend sudo (followed by a space) if you need information on ports below #1024.

Solution 2:[2]

I had application which was constantly restarting on port 80. I uninstalled the application and it solved it

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yao Li
Solution 2 deny7ko