mac terminal设置网络代理

发布时间 2023-03-23 18:24:24作者: saaspeter
我的mac浏览器是可以上github了,但是terminal怎么设置都不走代理(包括把整个无线网都设置为走代理,还是不通),curl https://github.com 不通,后来查了下,有人说terminal在mac设计的时候就是不走代理,不知道为什么apple这样设计。
 
在网上查了一下,以下两个是参考:
macOS - 给Terminal终端命令行配置网络代理的方法 (hangge.com)
MacOS设置终端代理 - 没有气的汽水 - 博客园 (cnblogs.com)
 
最终设置如下:
 vi ~/.zshrc
# 加上这两行
alias proxyon='export http_proxy=127.0.0.1:1087;export https_proxy=$http_proxy'
alias proxyoff='unset http_proxy;unset https_proxy’
 
source ~/.zshrc
 
在要打开proxy的时候,直接输入命令:proxyon , 要关闭的时候输入:proxyoff
 
请注意:不要使用这种方式: export all_proxy=socks5://127.0.0.1:1080,有的网页介绍中采用这种方式,使用socks5 proxy确实可以curl https://github.com, 但是在验证 curl -vvv -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install 的时候就错了,显示如下错误:SSL: no alternative certificate subject name matches target host name ‘raw.githubusercontent.com’ , 其实这个证书是对的,尽管common name是github.com,但在证书的san 中包含了githubusercontent.com,但如果proxy用了socks5就会出这样的错误,而使用http, https的proxy就好了。