安装polipo

brew install polipo

修改/usr/local/opt/polipo/homebrew.mxcl.polipo.plist文件配置本地代理,在array中增加<string>socksParentProxy=localhost:1087</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:1087</string>
    </array>
    <!-- Set `ulimit -n 20480`. The default OS X 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>20480</integer>
    </dict>
  </dict>
</plist>

设置开机启动

ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents

启动本地全局代理

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plis

确保已打开本地http代理的1087,图中未打开

此时即可在命令前添加http_proxy=http://localhost:8123来使用代理,区别以下效果

20:39:39-dylan~$ curl ip.gs
当前 IP:125.39.**.** 来自:中国
20:39:44-dylan~$ http_proxy=http://localhost:1087 curl ip.gs
当前 IP:210.140.**.** 来自:日本 
20:39:48-dylan~$ 

使用export http_proxy=http://localhost:1087为当前会话添加全局代理即可避免每次命行添加前缀,或者使用别名,或将export http_proxy=http://localhost:1087添加到.bashrc或者.bash_profile文件

注意,如果添加了开机启动和全局,所有的操作都会走本地代理,如果本身SS不稳定或者偶尔的波动会导致网络请求出现异常,如下

<head>
 <title>500 Internal Privoxy Error</title>
 <link rel="shortcut icon" href="http://config.privoxy.org/error-favicon.ico" type="image/x-icon"></head>
<body>
<h1>500 Internal Privoxy Error</h1>
<p>Privoxy encountered an error while processing your request:</p>
<p><b>Could not load template file <code>no-server-data</code> or one of its included components.</b></p>
<p>Please contact your proxy administrator.</p>
<p>If you are the proxy administrator, please put the required file(s)in the <code><i>(confdir)</i>/templates</code> directory.  The location of the <code><i>(confdir)</i></code> directory is specified in the main Privoxy <code>config</code> file.  (It's typically the Privoxy install directory, or <code>/etc/privoxy/</code>).</p>
</body>
</html>

建议需要时再按需采用.

标签: none

添加新评论