Apache2 – Netcat Connection Refused on Localhost

Apache2debiannetcat

I have installed webserver (apache) but I can't seem to make netcat connect to it.

$ curl localhost:80 | head
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10701  100 10701    0     0  2230k      0 --:--:-- --:--:-- --:--:-- 2612k

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Apache2 Debian Default Page: It works</title>
    <style type="text/css" media="screen">
  * {
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;

$ nc localhost 80
localhost [127.0.0.1] 80 (http) : Connection refused

I've also tried the same experiment with nginx before. With the same results.

I'm on debian and there's no firewall active, what am I doing wrong?

Best Answer

The problem was that the netcat that was installed was netcat-traditional which does not support IPV6 and for some reason both apache2 and nginx were listening only on the IPV6 loopback.

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

The solution was to install and use netcat from openbsd and netcat could connect with either nc ::1 80 or nc localhost 80.