在mac os中,非root用户是无法使用小于1024的常用端口的。如果开发中需要用到80端口, 就要设置端口转发
修改hosts文件
(1)打开Terminal,输入以下指令:
sudo vim /etc/hosts
(2)把test.com映射到本地后(test.com改成你要映射的域名)
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
#127.0.0.1 localhost
# 需要映射的域名
127.0.0.1 test.com
保存退出
端口转发
域名映射完成后,需要做的是端口转发,也就是将监听的80端口转发到8080(即本地项目启动端口)。
1.创建idea.tomcat.forwarding文件
sudo vim /etc/pf.anchors/idea.tomcat.forwarding
2.在idea.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