转载来自:https://www.hangge.com/blog/cache/detail_3138.html
1,确定代理客户端的端口
2,配置代理
1
|
vi ~/.bash_profile |
- 然后在其里面添加如下内容:
1
2
|
alias proxy= 'export http_proxy=127.0.0.1:1088;export https_proxy=$http_proxy' alias proxyOff= 'unset http_proxy;unset https_proxy' |
- 最后执行如下命令使配置生效:
1
|
source ~/.bash_profile |
(2)而从 macOS Catalina 版开始,Mac 将使用 zsh 作为默认的 Shell 终端。要对其进行配置,首先执行如下命令修改用户全局配置文件:
1
|
vi ~/.zshrc |
- 然后在其里面添加如下内容:
1
2
|
alias proxy= 'export all_proxy=socks5://127.0.0.1:1080' alias unproxy= 'unset all_proxy' |
- 最后执行如下命令使配置生效:
1
|
source ~/.zshrc |
3,开始测试
1
|
curl ipinfo.io |
1
|
proxy |
(3)再次使用 curl 命令查看可以发现变成了国外的 IP(代理服务器的 IP):
1
|
unproxy |
附:配置 Git、NPM 代理
1,配置 Git 代理
1
2
|
git config -- global http.proxy http: //127.0.0.1:1088 git config -- global https.proxy https: //127.0.0.1:1088 |
(2)执行如下命令则取消代理:
1
2
|
git config -- global --unset http.proxy git config -- global --unset https.proxy |
2,配置 NPM 代理
1
2
3
|
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 |
(2)执行如下命令则取消代理:
1
2
|
npm config delete proxy npm config delete https-proxy |