如何给 iTerm2 设置 SOCK5 代理?
Mac 上我使用的终端是 iTerm2,有时候要使用 git clone 仓库,有时候要使用 go get 下载依赖包,发现速度非常之慢,自然而然想到使用代理来解决,可是又有一个问题是我使用的是 ss,协议是 sock5,而 iTerm2 只支持 http 的代理协议。
经过搜索后,发现在 mac 上有一个工具叫 privoxy,它可以将 http 代理转成 sock5 代理。
Privoxy 代理配置
MacOS 安装Privoxy比较简单,一条命令即可
brew install privoxy
安装完后,要先创建 config 文件(需要先创建文件夹)
sudo mkdir -p /usr/local/etc/privoxy/
sudo touch /usr/local/etc/privoxy/config
然后编辑vim /usr/local/etc/privoxy/config
8087
是本机要监听的http代理地址1080
是SS的socks5代理地址,还设置本地地址
listen-address 127.0.0.1:8087
forward-socks5 / 127.0.0.1:7891 .
然后先使用如下命令,尝试一下配置有没有问题
privoxy /usr/local/etc/privoxy/config
若没有问题的话,改用 brew 来启动服务
brew services start privoxy
iTerm2 代理配置
通过下面的环境变量就可以设置http代理。
export http_proxy=http://127.0.0.1:8087
export https_proxy=$http_proxy
你可以把它们写在 ~/.zshrc
或者 ~/.bash_profile
中,随时切换。
alias goproxy='export http_proxy=http://127.0.0.1:8087 https_proxy=http://127.0.0.1:8087'
alias disproxy='unset http_proxy https_proxy'