mac下8080端口到80端口的转发

    xiaoxiao2021-04-15  26

    MAC OS 本质上还是 Unix 系统, Unix 系统大多默认情况下非root用户是无法使用小于1024的常用端口的.这时候如果你开发中需要在普通用户下用到 80端口, 比如 tomcat, 比如 vitualbox 下构建了一个 http 服务, 若你想直接通过 浏览器的 localhost 访问的话(不用加上莫名其妙的”:端口”的话)你就需要做一些 系统端口转发的工作.

    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 8443

    2、创建文件 :

    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
    转载请注明原文地址: https://ju.6miu.com/read-671734.html

    最新回复(0)