Mac 使用 80 端口

avatar 2018年05月13日17:45:39 6 2835 views
博主分享免费Java教学视频,B站账号:Java刘哥
  • [ ] 方案一: Mac OS X 因为要绑定80端口需要ROOT权限, 但是如果用root权限启动eclipse或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除,放弃
  • [x] 方案二: 通过pfctl做网络层的端口转发, 让连接到本机80端口的请求,都转发到8080端口;采纳
注意, Mac OS 会使用80端口做网络文件共享,要先关闭掉。  

一、修改/etc/pf.conf

先对pf.conf进行备份:
  1. sudo cp /etc/pf.conf /etc/pf.conf.normal.bak
  之后在该文件中以下行:
  1. sudo vim /etc/pf.conf
  rdr-anchor "com.apple/*" 后面添加一行配置,如下:
  1. rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
 

二、依次执行以下命令:

  1. sudo pfctl -d
  2. sudo pfctl -f /etc/pf.conf
  3. sudo pfctl -e

注意:如果有apache等服务器占用了80端口,则需要将其停掉方能成功!

如果出现 No ALTQ support in kernel ALTQ related functions disabled pfctl: pf not enabled  

问题一:getsockopt: connection refused(暂时未遇到)

  1. 2017/08/07 18:47:52 [E] [proxy.go:332] [sell] connect to local service [127.0.0.1:80] error: dial tcp 127.0.0.1:80: getsockopt: connection refused
上面我们配置pfctl转发到8080端口,当时有效,但因为重启电脑后,pfctl的配置又变回之前了,需要配置在开机启动的配置文件中。 注:开机启动需要编辑文件 /System/Library/LaunchDaemons/com.apple.pfctl.plist
  1. <string>pfctl</string>
  2. <string>-e</string>
  3. <string>-f</string>
  4. <string>/etc/pf.conf</string>
10.11以上系统因为增强了安全模式,导致/System/Library/LaunchDaemons/com.apple.pfctl.plist修改失败,请重启至安全模式在进行操作。   原文地址:https://blog.csdn.net/inke88/article/details/76677911  
  • 微信
  • 交流学习,有偿服务
  • weinxin
  • 博客/Java交流群
  • 资源分享,问题解决,技术交流。群号:590480292
  • weinxin
avatar

发表评论

avatar 登录者:匿名
匿名评论,评论回复后会有邮件通知

  

已通过评论:0   待审核评论数:0