Idea Mac OS 80端口被占用
一、概述
用Mac电脑做开发时,经常会碰到远程调试或者调用时需要用80端口来启动WEB服务,Intellij IDEA上把tomcat的默认端口改成80,启动web应用时一直提示80端口被占用。使用lsof -i:80命令查找发现是Chrome浏览器占用80端口,然后杀掉浏览器进程再次启动web应用,仍然提示80端口被占用。经过Google发现是由于 Mac 系统限制非root用户不能启动1024以下端口,而我们平时使用Mac一般都是非root用户,所以如果想启动80端口必须用root用户。比如启动nginx,必须使用sudo nginx ,但是如果用root权限启动nginx或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除。尤其是使用公司的电脑安装了权限控制。。。这真是让人头疼的问题?
二、解决方案
解决方法:可以通过pfctl做网络层的端口转发, 让连接到本机80端口的请求, 都转发到8080端口。
- 用管理员权限打开编辑pf.conf文件,命令如下:
sudo vim /etc/pf.conf
- 在 rdr-anchor "com.apple/*" 这一行的后面添加一行,如下所示:
rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
注意:conf是对顺序强要求的, 所以注意添加的内容放的顺序。效果如下:
# Default PF configuration file.
# This file contains the main ruleset, which gets automatically loaded
# at startup. PF will not be automatically enabled, however. Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8). That will ensure that PF
# is disabled only when the last enable reference is released.
#
# Care must be taken to ensure that the main ruleset does not get flushed,
# as the nested anchors rely on the anchor point defined here. In addition,
# to the anchors loaded by this file, some system services would dynamically
# insert anchors into the main ruleset. These anchors will be added only when
# the system service is used and would removed on termination of the service.
#
# See pf.conf(5) for syntax.
# com.apple anchor point
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
- 其中lo0是绑定了127.0.0.1的网络设备名称,具体可以使用ifconfig查看。在tomcat的配置中,设定启动端口为8080,依次执行如下命令让端口转发马上生效:
sudo pfctl -d #第一步sudo pfctl -f /etc/pf.conf #第二步sudo pfctl -e #第三步
在执行上述命令的过程中如果发现如下提示,忽略之即可:
No ALTQ support in kernel
ALTQ related functions disabled
pfctl: pf already enabled
最后启用之前请先停掉其他占用80端口的进程如nginx等应用。项目启动成功n(*≧▽≦*)n
Idea Mac OS 80端口被占用相关推荐
- mac上启动nginx遇到80端口被占用的解决方法(猜了好久的坑我擦)
今天启动nginx的时候,发现80端口被占用,用ps -ef | grep nginx和lsof -i:80都找不到,后来上网搜索后发现是apache的问题,是因为系统自带的apache启动了所以占用 ...
- Mac 使用 80 端口
Mac 使用 80 端口 更新日志: 20170807 更新mac使用80端口的错误问题. Mac 使用 80 端口 一修改etcpfconf 二依次执行以下命令 注意如果有apache等服务器占用了 ...
- windows 80端口被占用的解决方法
参考文献: 文献1: http://wenku.baidu.com/view/af4681bcfd0a79563c1e7289.html 文献2: http://www.2cto.com/os/201 ...
- linux查询80端口,Linux 查看 80 端口的占用情况
lsof -i:端口号 eg: lsof -i:80 lsof -i:21 [root@localhost ~]# lsof -i: COMMAND PID USER FD TYPE DEVICE S ...
- MacOS提示80端口被占用
Intellij IDEA上把tomcat的默认端口改成80,运行web应用时提示80端口被占用 使用lsof -i:80命令找不到是哪个程序占用了80端口 由于 Mac 系统限制非root用户不能启 ...
- apache的80端口被占用【已解决】
十分感谢作者.转载:http://www.2cto.com/os/201111/111269.html 转过来做个记录. 前段时间停止了Apache,结果在打开的时候发现无法打开,80端口被占用,于是 ...
- Apache安装80端口被占用解决方案
Windows系统 如果80端口被占用,安装Apache的过程中,可能无法成功安装Apache的Servcie.如果不能正确安装Apache Service,那么执行Start或Restart等命令时 ...
- 80端口被占用pid 4,svhost等占用的解决方法
80端口被占用pid 4,svhost等占用的解决方法 参考文章: (1)80端口被占用pid 4,svhost等占用的解决方法 (2)https://www.cnblogs.com/joma/arc ...
- xampp mysql 端口被占用_xampp安装后apache 80端口被占用的解决方法
这篇文章主要介绍了xampp安装后apache 80端口被占用的解决方法,大家参考使用吧 xampp 把apache mysql, php, phpmyadmin都integrate在一起, 很好安装 ...
最新文章
- 自定义对话框控件bate2----20050516
- sshpass做秘钥分发,ansible做自动化运维工具
- C# 无意间写了一段线程死锁的代码
- bash资源监控_10个资源成为更好的Bash用户
- 决定你是富人还是穷人的12条定律
- seq2seq模型_用 CNN 实现 Seq2Seq 模型
- C语言实现windows进程遍历
- 时间序列分析工具箱—— h2o + timetk
- 查看计算机GUID的WMI类
- 译:Self-Modifying cod 和cacheflush
- 超好用的代码格式化工具Astyle使用
- 64qam星座图matlab,16QAM_星形和矩形星座图调制解调MATLAB代码(最新整理)
- HTML5基础语法详述
- 光纤通道FC存储交换机的常见问题详解
- ai画面怎么调大小_AI里面怎么改变文件的大小?
- Python3 语音识别谷歌验证码
- 单位旧计算机处理,单位出售旧电脑增值税税率是多少?
- android 画三角形
- NetDevOps的理解与学习路线
- 【关于理想】别让你的理想显得太掉价,每个人都很值钱