mac與linux一樣,1024以下的端口為特權(quán)端口,只有root用戶才有權(quán)監(jiān)聽(tīng)。
因此要使用80端口要么使用root啟動(dòng)tomcat,要么使用端口轉(zhuǎn)發(fā)。
使用ipfw(Internet Protocol Firewall)設(shè)置端口轉(zhuǎn)發(fā)
ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in
不過(guò)ipfw已經(jīng)被標(biāo)記為廢棄狀態(tài)。
使用pf(packet filter)設(shè)置端口轉(zhuǎn)發(fā)
1.創(chuàng)建anchor文件
sudo vi /etc/pf.anchors/tomcat
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
2.測(cè)試anchor文件是否正確配置
pfctl -vnf /etc/pf.anchors/tomcat
如果正確會(huì)顯示
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.
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port = 80 -> 127.0.0.1 port 8080
添加到主配置文件
pf啟動(dòng)時(shí)會(huì)自動(dòng)裝載/etc/pf.conf文件,因此將anchor文件鏈接到/etc/pf.conf,轉(zhuǎn)發(fā)規(guī)則就會(huì)自動(dòng)建立了。
rdr-anchor "tomcat-forwarding"
load anchor "tomcat-forwarding" from "/etc/pf.anchors/tomcat"
注意要緊隨文件中現(xiàn)有的anchor后面添加上面兩行
有的電腦 需要嚴(yán)格按照上面的順序來(lái)
打開(kāi)pf
pf默認(rèn)是關(guān)閉的。可以使用以下命令啟動(dòng)pf:
pfctl -e /etc/pf.conf
也可以使用其他配置文件啟動(dòng)pf。
也可以修改LaunchDaemons來(lái)使pf開(kāi)機(jī)自動(dòng)打開(kāi)。
/System/Library/LaunchDaemons/com.apple.pfctl.plist
<key>ProgramArguments</key>
<array>
<string>pfctl</string>
<string>-e</string>
<string>-f</string>
<string>/etc/pf.conf</string>
</array>
添加的為-e參數(shù),即enable