Can't listen on port 80 with my server
Solution 1
If this is Linux (and perhaps some other UNIXes as well, though not MacOS), try running the following:
sudo netstat -lnp
You'll get output similar to the following:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
...
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26156/apache2
...
I'll list the interesting parts:
- Local Address: 0.0.0.0:80 - The address in question is port 80 on all interfaces.
- State: LISTEN - It's listening
- PID/Program name - 26156/apache2 - The ID and name of the process that's listening to the port.
You basically want to to make sure the program mentioned above isn't running (e.g., in my case, I'd have to shutdown the apache2 daemon, and configure the OS to not automatically start it up on next boot).
On the other hand, if you just want to get this fixed quickly, you can kill the process:
kill -9 <pid>
In my example:
kill -9 26156
The problem will of course return the next time you reboot, or someone starts up that service.
Solution 2
You can use lsof
to find out:
sudo lsof -i :80
If you don't have lsof
, install it with
sudo apt-get install lsof
lsof
is like swiss army knife tool to tell who is holding files and sockets open.
Ludo
Updated on November 23, 2020Comments
-
Ludo over 3 years
Very new on this kind of issue, i am trying to launch a server on the port 80 (it's important to me to use this specific port).
It's fails, but it works on other ports (even < 1024 when i am root, but still fail on the port 80).
I probably have something running on the port 80, i would like to identify it in order to change its listening port.
I saw this cmd can help to see the state of a specific port:
netstat -ano|grep 80|grep LISTEN
but i am not sure tu understand well the result.Here is what i get:
tcp 0 0 127.0.0.1:28017 0.0.0.0:* LISTEN off (0.00/0/0) tcp6 0 0 :::80 :::* LISTEN off (0.00/0/0) unix 2 [ ACC ] STREAM LISTENING 8805 /tmp/mongodb-27017.sock unix 2 [ ACC ] STREAM LISTENING 13112 /home/me/.pulse/04d802bb34ddb9da49b1f9060000000b-runtime/native
I read on the line 2 that the port 80 seems to be not listening, but don't understand further.
UPDATE:
sudo lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 1107 root 4u IPv6 7630 0t0 TCP *:http (LISTEN) apache2 1131 www-data 4u IPv6 7630 0t0 TCP *:http (LISTEN) apache2 1132 www-data 4u IPv6 7630 0t0 TCP *:http (LISTEN) apache2 1133 www-data 4u IPv6 7630 0t0 TCP *:http (LISTEN) apache2 1134 www-data 4u IPv6 7630 0t0 TCP *:http (LISTEN) apache2 1136 www-data 4u IPv6 7630 0t0 TCP *:http (LISTEN) ubuntu-ge 2095 me 7u IPv4 82145 0t0 TCP me-Ubuntu.local:43345->mulberry.canonical.com:http (CLOSE_WAIT)
Thanks (i am using ubuntu) !
-
Jack Leow over 11 yearsIs this Linux? Or some other flavor of UNIX?
-
Devin Stewart over 11 yearsthe :::80 is telling you something is listening of port 80 via ipv6, :: is the equivalent of 0.0.0.0 in ipv4. mvp's answer below should give you what process is running on port 80 currently.
-
Kien Truong over 11 yearsShouldn't this be on Serverfault ?
-
Eliah Kagan over 11 yearsThis will likely be considered off-topic for Stack Overflow. You might want to ask about this on Ask Ubuntu, Unix.SE, or Super User (but search for it there first!).
-
-
Ludo over 11 yearsI updated the main post with the result, Apache seems to be listening on this port, but i guess it have to in order to match the HTTP requests...? (Sorry i am lost^^)
-
Ludo over 11 yearsOk thanks for the explanations, yes apache is the program running on port 80 in my case too. Is it a good id to change its port ? I guess apache has to match the http requests so i don't want to do some wrong opearations on it...
-
mvp over 11 yearsYou must have another apache instance started and bound to port 80. You should stop it first:
sudo service apache2 stop
. In other words, lsof should not show any process listening on 80, otherwise you will not be able to start another one. -
Ludo over 11 yearsYes i understood this point but is there a way to make apache working on another port ? Because i need it to make my domain match with a specific path (where there is my webapp), then i need a nodejs server listening on port 80.
-
mvp over 11 yearsyes, you can make apache work on any port. But remember that any other port most likely will be firewalled for most users of your site. Better option would be to use ProxyPass from Apache into nodejs working on some internal port
-
Jacek Pietal over 4 yearsworks in my case showed apache2 which i stopped as a daemon >;-O