問題
mac電腦的80端口使用不了,除非用root,又不太安全,采用轉發的話會好很多
方法
1 在/etc/pf.anchors/目錄下建立一個 my.forwarding檔案
sudo touch /etc/pf.anchors/my.forwarding
插入以下内容
rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 10080
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 10443
2 在/etc/目錄下建立my.conf檔案
touch /etc/pf-my.conf
rdr-anchor "my.forwarding"
load anchor "my.forwarding" from "/etc/pf.anchors/my.forwarding"
3 執行
pfctl -vnf /etc/pf-my.conf
檢查配置檔案有沒有問題
4 執行
sudo pfctl -F all -ef /etc/pf-my.conf
讓端口轉發生效
5 執行
sudo pfctl -s nat
檢視是否生效
若出現以下輸出則證明端口轉發成功
rdr-anchor "my.forwarding" all
6 現在啟動服務,就可以把80轉發到10080了