The port 80 in Mac is used

2020-05-25 07:53发布

We have to use port 80 for our server. But when I was trying to use it in Mac, it always said that the 80 is used, but I don't know which program uses it.

I searched it in Google, and someone said it's about apache, but I tried, which is not working. I found this: https://gist.github.com/kujohn/7209628 , but seems it's not working visiting our server by IP address.

I really don't know what's going on and how can I find out which program using port 80 and stop it.

Many thanks if anyone can help, I'm new using Mac. Thanks.

6条回答
劳资没心,怎么记你
2楼-- · 2020-05-25 07:53

Port numbers in the range from 0 to 1023 are classified as 'well-known' and port number 80 is reserved for HTTP. Typically you have servers listening on port 80 to handle HTTP requests.

Source: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

查看更多
Lonely孤独者°
3楼-- · 2020-05-25 07:59

To find out what process is using port 80

  1. go to Applications
  2. open utilities.
  3. open Activity Monitor.
  4. click on the Memory tab,
  5. look at the ports and the processes using them. Find port 80 and select it
  6. go to the view on the menu bar and choose Quit process.

This will just kill the process, it will not stop a server instance that is already running from continuing to run.

It is not clear if you are using a database management system or not and which one but one method that has worked for me using MAMP is as follows.

  • stop the server by using sudo apachectl stop command.
  • then change the port to port 80.
  • then restart your servers.
查看更多
三岁会撩人
4楼-- · 2020-05-25 08:03

I was having this issue, apache was disabled via launchctl, but was still tying up port 80 after launch, I could start up apache and it would work, but after unloading it, I couldn't start up anything on port 80. I was using the built in web server for Python as an easy test. It would work on port 81, but not on port 80.

sudo python -m SimpleHTTPServer 80 -- wouldn't work

sudo python -m SimpleHTTPServer 81 -- would work

Here are the symptoms:

$ launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 
/System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service
$ sudo lsof -i ':80'
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Python  3353 root    3u  IPv4 0xe455777a82799f05      0t0  TCP *:http (LISTEN)

The fix for me (after way too much searching) was simple:

sudo pfctl -F all

This flushed the packet filter, releasing port 80 (and others I assume 8080, 443, whatever ports apache might be tying up)

After that, and relaunching the python server, it came right up.

查看更多
萌系小妹纸
5楼-- · 2020-05-25 08:05

On Mac ports below 1024 can only be bound by the root user. Try launching your server as root user (with sudo), or try to use a port above 1024.

You can also try to add root permissions to your user in /etc/sudoers

# root and users in group wheel can run anything on any machine as any user
root            ALL = (ALL) ALL
%admin          ALL = (ALL) ALL
your_user_here  ALL = (ALL) ALL
查看更多
地球回转人心会变
6楼-- · 2020-05-25 08:08

type the following in Terminal

sudo lsof -i -n -P | grep TCP

you will get a list - e.g. dropbox listens on 80
you can copy the output to a text editor, etc to search

查看更多
欢心
7楼-- · 2020-05-25 08:18

Might be Skype that is using port 80. If you have Skype installed and running try to change to a different port in the settings.

查看更多
登录 后发表回答