zoukankan      html  css  js  c++  java
  • mac下8080端口到80端口的转发

    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

  • 相关阅读:
    透过书本了解HTML5
    Seam性能讨论
    Maven依赖管理
    Tapestry
    为HTML5的未来制定学习计划
    后缀数组
    HDU 1042(大数)
    教你理解复杂的C/C++声明
    编程修养
    平衡二叉树
  • 原文地址:https://www.cnblogs.com/yanglei-xyz/p/14749832.html
Copyright © 2011-2022 走看看