MAC终端代理到外网设置
目录
MAC终端代理到外网设置
移动开发有时需要设置代理,不然太慢。在~/.bash_profile 文件中(此文件可能没有,没有就创建一个)添加如下代码
function proxy_off(){
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
echo -e "已关闭代理"
}
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export http_proxy="http://127.0.0.1:1087"
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export FTP_PROXY=$http_proxy
export RSYNC_PROXY=$http_proxy
echo -e "已开启代理"
}
其中的 http_proxy 是你自己设置的本地代理,不是我们买的外面的代理地址,一般都是如上面代码所示,一般不用改。
端口的话 有可能不是1087,这个要看本地服务的HTTP代理端口了,一般ss的默认端口是1087,如果你没改过的话。
然后执行source ~/.bash_profile 使其立刻生效
使用时需要打开你代理工具的全局模式(不要使用PAC模式),然后打开终端
只需要输入proxy_on就会启动代理
判断终端是否走了代理服务器的方法
curl cip.cc
对比下设置前后是否有区别
该设置仅对当前终端窗口生效,关闭窗口,下次需要再设置一次proxy_on
实际演示
上图展示了从杭州 proxy_on 到了洛杉矶,然后又 proxy_off 回杭州的过程。
写的很细啦,如果帮到你了请点个赞,谢谢。