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
  • 相关阅读:
    正则表达式工具RegexBuddy使用教程(原创自Zjmainstay)
    基于nodejs实现js后端化处理
    深入正则表达式应用
    如何利用火狐控制台下载网页图片
    Ajax实现提交表单时验证码自动验证(原创自Zjmainstay)
    PHP cURL应用实现模拟登录与采集使用方法详解
    程序猿教你怎样记密码
    我眼里的正则表达式(入门)
    博客园文章markdown实现
    jQuery实现菜单点击隐藏(上下左右)
  • 原文地址:https://www.cnblogs.com/chenmo-xpw/p/5519593.html
Copyright © 2011-2022 走看看