利用VPS为终端设置SS代理服务

为什么要设置终端代理服务

在看influxdb源码的时候,需要使用dep ensure来安装influxdb的依赖包。但是出现了一些依赖包下不过来的问题,才发现需要终端挂代理才可以。

如何设置终端SS代理服务

首先需要了解终端SS代理服务的原理,SS是我们常用的代理工具,但是这个工具使用是socks5协议。但是终端一般都是只支持HTTP等协议。所以我们需要一个中间工具把socks5协议转为终端可以支持的HTTP协议。

准备工作

首先需要配置一个SS,如果不知道如何配置或者没有购买的话就使用搬瓦工。具体使用这里就不多讲了,可以自己查找。

终端配置

安装polipo 工具

polipo工具就为我们将socks5协议转化为http协议的工具

mac

brew install polipo

polipo登录启动

  1. 执行 ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents
  2. 执行 vim /usr/local/opt/polipo/homebrew.mxcl.polipo.plist
    在其中添加<string>socksParentProxy=localhost:1080</string>,结果如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.polipo</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/polipo/bin/polipo</string>
<!--添加这一行-->
<string>socksParentProxy=localhost:1080</string>
</array>
<!-- Set ulimit -n 65536. The default macOS limit is 256, that's
not enough for Polipo (displays 'too many files open' errors).
It seems like you have no reason to lower this limit
(and unlikely will want to raise it). -->
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>65536</integer>
</dict>
</dict>
</plist>

启动和关闭polipo

// 关闭
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
// 启动
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist

至此全部的工作已经结束,你只需要启动polipo即可。然后在终端发送http_proxy=http://localhost:8123 curl ip.gs进行测试。
利用VPS为终端设置SS代理服务
但是每条命令都需要设置代理是非常麻烦的,那么就参考其他工作的内容。

其他工作

  1. 设置别名(使用更加方便,强烈推荐配置)
  2. linux下配置

猜你喜欢

转载自blog.51cto.com/13589319/2119245