大数据(BD社区)-专业IT技术社区

?找回密码
?bet36体育在线网站

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 404|回复: 0
打印 上一主题 下一主题

解决Mac 80端口被占用

[复制链接]

70

主题

73

帖子

389

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
389
跳转到指定楼层
楼主
发表于 2019-5-16 09:35:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在做一些第三方登录开发调试、微信小程序等开发时,必须要用本机的80端口。但是,mac却禁止了普通用户访问1024以下的端口,包括80端口,因为mac会用这些端口来提供文件共享等等很多服务。

解决办法:停掉mac自带的占用80端口的程序(其实就是一个apache),然后再设置端口转发,将80端口的请求转发到8080或9090端口。

具体操作如下:

一、关闭占用80端口的apache:sudo apachectl stop
二、修改/etc/pf.conf,设置端口转发:
sudo vi /etc/pf.conf 在 rdr-anchor "com.apple/*" 后添加 rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080,修改后的效果:
  1. #
  2. # Default PF configuration file.
  3. #
  4. # This file contains the main ruleset, which gets automatically loaded
  5. # at startup.??PF will not be automatically enabled, however.??Instead,
  6. # each component which utilizes PF is responsible for enabling and disabling
  7. # PF via -E and -X as documented in pfctl(8).??That will ensure that PF
  8. # is disabled only when the last enable reference is released.
  9. #
  10. # Care must be taken to ensure that the main ruleset does not get flushed,
  11. # as the nested anchors rely on the anchor point defined here. In addition,
  12. # to the anchors loaded by this file, some system services would dynamically
  13. # insert anchors into the main ruleset. These anchors will be added only when
  14. # the system service is used and would removed on termination of the service.
  15. #
  16. # See pf.conf(5) for syntax.
  17. #

  18. #
  19. # com.apple anchor point
  20. #
  21. scrub-anchor "com.apple/*"
  22. nat-anchor "com.apple/*"
  23. rdr-anchor "com.apple/*"
  24. rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 9090
  25. dummynet-anchor "com.apple/*"
  26. anchor "com.apple/*"
  27. load anchor "com.apple" from "/etc/pf.anchors/com.apple"
复制代码
  1. lo0 通过ifconfig 看自己那个设备绑定的是127.0.0.1, lo0是这个网络设备的名字
复制代码
三、使修改生效,依次执行以下命令:
  1. sudo pfctl -d
  2. sudo pfctl -f /etc/pf.conf??
  3. sudo pfctl -e??
复制代码
完成,可以测试效果了!

本版积分规则

Archiver|手机版|小黑屋|BD Inc. ( 京ICP备16038882号-2 )

GMT+8, 2019-10-24 03:03 , Processed in 0.027945 second(s), 17 queries .

Powered by Discuz! X3.4

? 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表