46

给 iTerm 设置代理

 5 years ago
source link: https://colobu.com/2018/09/05/set-proxy-for-iterm/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如果你用SS FQ的话, Shadow-Socks设置的系统代理是socks5代理,在iTerm中访问一些https还是不能用, 比如用 go get 下载一些依赖的库。一个办法就是使用Privoxy将socks5代理转换成http代理。

Privoxy

MacOS安装Privoxy比较简单。

-> brew install privoxy


==> Downloading https://homebrew.bintray.com/bottles/privoxy-3.0.26.sierra.bottl
######################################################################## 100.0%
==> Pouring privoxy-3.0.26.sierra.bottle.1.tar.gz
==> Caveats
To have launchd start privoxy now and restart at login:
  brew services start privoxy
Or, if you don't want/need a background service you can just run:
  privoxy /usr/local/etc/privoxy/config
==> Summary
?  /usr/local/Cellar/privoxy/3.0.26: 52 files, 1.8MB

你可以使用 brew services start privoxy 启动privoxy服务,或者手工临时启动 privoxy /usr/local/etc/privoxy/config 也可以。

如果中间需要 brew link privoxy 按照提示创建文件夹,比如 /usr/local/sbin ,设置对应的权限即可。

启动服务前先编辑 vim /usr/local/etc/privoxy/config

listen-address 127.0.0.1:8118
forward-socks5 / 127.0.0.1:1080 .

forward 192.168.*.*/ .
forward 10.*.*.*/ .
forward 127.*.*.*/

8118 是本机要监听的http代理地址, 1080 是SS的socks5代理地址,还设置本地地址。

配置http代理

通过下面的环境变量就可以设置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'

参考

  1. https://segmentfault.com/a/1190000008848001
  2. https://honglu.me/2015/11/06/给iTerm终端设置代理/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK