My hosts file maps 127.0.0.1 to localhost.
127.0.0.1
localhost
$ curl -I \'localhost\' curl: (7) Failed to connect to localhost port 80: Connection re
In my case, the file ~/.curlrc had a wrong proxy configured.