轉載來自: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 |