1、获取端口
在代理工具中获取其开放的 HTTP 端口,比如这里使用的端口是 1088
2、配置代理
bash 终端
bash 是 macOS Mojave 及更低版本中的默认 Shell 终端
a) 打开终端文件
- 方法一:使用命令行
vi ~/.bash_profile
- 方法二:直接在Finder中手动打开,
.bash_profile
文件默认隐藏,在user
的主目录中键盘输入快捷键command + shift + .
开启隐藏文件,如果没有.bash_profile
文件,我们可以手动创建,文件目录在user
的主目录下。
b) 配置内容
在.bash_profile
文件内容最后新起一行,输入以下内容并【保存】。
其中端口号127.0.0.1:1088
根据自己的工具开放端口配置
proxy
和 proxyOff
是执行代理开关的便捷终端命令
alias proxy='export http_proxy=127.0.0.1:1088;export https_proxy=$http_proxy'
alias proxyOff='unset http_proxy;unset https_proxy'
c) 配置内容
Terminal终端执行配置文件生效命令
source ~/.bash_profile
zsh 终端
zsh 是 macOS Catalina 及更高版本中的默认 Shell 终端
1、打开终端文件
- 方法一:使用命令行
vi ~/.zshrc
- 方法二:直接在Finder中手动打开,
.bash_profile
文件默认隐藏,在user
的主目录中键盘输入快捷键command + shift + .
开启隐藏文件,如果没有.bash_profile
文件,我们可以手动创建,文件目录在user
的主目录下。
2、配置内容
在.zshrc
文件内容最后新起一行,输入以下内容并【保存】,
其中端口号127.0.0.1:1088
根据自己的工具开放端口配置
proxy
和 unproxy
是执行代理开关的便捷终端命令
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'
3、配置内容
Terminal终端执行配置文件生效命令
source ~/.zshrc
3、开始测试
1) 查看本地 IP
curl ipinfo.io
输出:
xxxxx@xxxxxMacBook-Pro ~ % curl ipinfo.io
{
"ip": "xx.xx.xxx.x",
"city": "Shanghai",
"region": "Shanghai",
"country": "CN",
"loc": "xx.,xxxx.xxx.xxxx",
"org": "ASxxxx Shanghai Mobile Communications Co.,Ltd.",
"timezone": "Asia/Shanghai",
"readme": "https://ipinfo.io/missingauth"
}%
2) 开启代理
proxy
再次查看本地 IP ,输出:
xxxxx@xxxxxMacBook-Pro ~ % curl ipinfo.io
{
"ip": "xx.xx.xxx.x",
"hostname": "xxx-xxx-xxx-xx.dynamic-ip.hinet.net",
"city": "Taipei",
"region": "Taiwan",
"country": "TW",
"loc": "xx.,xxxx.xxx.xxxx",
"org": "ASxxxx Data Communication Business Group",
"timezone": "Asia/Taipei",
"readme": "https://ipinfo.io/missingauth"
}%
3) 关闭代理
unproxy
4、配置 GIT 代理
设置代理
git config --global http.proxy http://127.0.0.1:1088
git config --global https.proxy https://127.0.0.1:1088
查看当前代理
xxxx@xxxMacBook-Pro ~ % git config --global -l
core.ignorecase=false
user.name=”xxxx”
user.email=”xxxx.com”
http.proxy=http://127.0.0.1:1088
https.proxy=https://127.0.0.1:1088
取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
5、配置 NPM 代理
设置代理
npm config set proxy http://127.0.0.1:1088
npm config set https-proxy http://127.0.0.1:1088
npm config set strict-ssl false
取消代理
npm config delete proxy
npm config delete https-proxy