Mac 使用 80 端口

Mac 使用 80 端口

更新日志:
20170807 更新mac使用80端口的错误问题。

  • [ ] 方案一:
    Mac OS X 因为要绑定80端口需要ROOT权限, 但是如果用root权限启动eclipse或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除,放弃

  • [x] 方案二:
    通过pfctl做网络层的端口转发, 让连接到本机80端口的请求,都转发到8080端口;采纳

注意, Mac OS 会使用80端口做网络文件共享,要先关闭掉。

一、修改/etc/pf.conf

先对pf.conf进行备份:

sudo cp /etc/pf.conf /etc/pf.conf.normal.bak

之后在该文件中以下行:

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

注意:lo0 通过ifconfig 看自己那个设备绑定的是127.0.0.1, lo0是这个网络设备的名字,一般大家都是lo0。如图:

二、依次执行以下命令:

sudo pfctl -d
sudo pfctl -f /etc/pf.conf  
sudo pfctl -e 

注意:如果有apache等服务器占用了80端口,则需要将其停掉方能成功!

如果出现

No ALTQ support in kernel
ALTQ related functions disabled
pfctl: pf not enabled

忽略即可。



问题一:getsockopt: connection refused

2017/08/07 18:47:52 [E] [proxy.go:332] [sell] connect to local service [127.0.0.1:80] error: dial tcp 127.0.0.1:80: getsockopt: connection refused

上面我们配置pfctl转发到8080端口,当时有效,但因为重启电脑后,pfctl的配置又变回之前了,需要配置在开机启动的配置文件中。
注:开机启动需要编辑文件 /System/Library/LaunchDaemons/com.apple.pfctl.plist

<string>pfctl</string>
<string>-e</string>
<string>-f</string>
<string>/etc/pf.conf</string>

10.11以上系统因为增强了安全模式,导致/System/Library/LaunchDaemons/com.apple.pfctl.plist修改失败,请重启至安全模式在进行操作。

参考自:
https://toutiao.io/posts/d7ljnp/preview
http://blog.csdn.net/thc1987/article/details/53606603
http://blog.csdn.net/ilovesmj/article/details/51549119
http://www.cnblogs.com/fullstack-yang/p/6223960.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在nginx中配置https转发80端口,可以使用以下配置: server { listen 443 ssl; server_name example.com; ssl_certificate /path/to/certificate.crt; ssl_certificate_key /path/to/private.key; location / { proxy_pass http://localhost:80; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; } } 上述配置中,监听443端口并启用SSL,使用的证书和私钥文件需要替换为实际的路径。然后通过设置proxy_pass将请求转发到后端的80端口。同时,需要设置适当的代理头信息,例如Host、X-Real-IP和X-Forwarded-Proto,以便正确地传递客户端的请求。这样配置后,nginx将会对收到的https请求进行转发,将请求发送到后端的80端口上。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [Nginx服务器中配置非80端口端口转发方法详解](https://download.csdn.net/download/weixin_38655496/14092017)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Mac使用Nginx实现80端口转发8080端口](https://download.csdn.net/download/weixin_38703968/12900530)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值