MAC OS 10.10 上 pfctl 就可以做这一件事情, 详情请参见
1、创建文件 :
sudo vim /etc/pf.anchors/eclipse.tomcat.forwarding文件内容 :
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080 rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 84432、创建文件 :
sudo vim /etc/pf-tomcat.conf文件内容 :
rdr-anchor "forwarding" load anchor "forwarding"from "/etc/pf.anchors/eclipse.tomcat.forwarding" 3、启动 sudo pfctl -ef /etc/pf-tomcat.conf 执行结果 root@ymdeMacBook-Air etc# sudo pfctl -ef /etc/pf-tomcat.conf pfctl: Use of -f option, could result in flushing of rules present in the main ruleset added by the system at startup. See /etc/pf.conf for further details. No ALTQ support in kernel ALTQ related functions disabled pf enabled 假设你的工程 http://localhost/myDemo.html 这时访问你的web工程, 你会发现 http://localhost/myDemo.html 这个不需要8080端口即可访问,加上 http://localhost:8080/myDemo.html 访问不了。 4、关闭 sudo pfctl -d 执行结果 root@ymdeMacBook-Air etc# sudo pfctl -d No ALTQ support in kernel ALTQ related functions disabled pf disabled 这时你访问你的web工程, 你会发现 http://localhost/myDemo.html 这个访问不了,加上 http://localhost:8080/myDemo.html 即可访问。 或者全部关闭 pfctl -F all -f /etc/pf.conf