mac上使用polipo将socks5代理转为http代理

其实以前一直很少用到http代理,因为浏览器解决大部分问题,直到我开始编译opencv才发现编译过程中还需要下载文件,在没有设置http代理的情况下会发生各种错误。
所以研究了一下几个软件,决定使用polipo。
以下是安装和配置方法:

  • 安装
brew install polipo
  • 修改配置文件
vim /usr/local/opt/polipo/homebrew.mxcl.polipo.plist
  • 配置文件代码根据自己的来修改socksParentProxy=localhost:1080改为你自己的socks代理地址。
<?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
ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
  • 关闭polipo
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
  • 在用户profile中设置alias实现terminal中快速设置和取消代理,source之使其生效。
alias proxy="export http_proxy=http://localhost:8123;export https_proxy=http://localhost:8123"  # 开启
alias unproxy="unset http_proxy"  # 关闭

配置完这个,发现还有个软件mellow-io/mellow: Mellow is a rule-based global transparent proxy client for Windows, macOS and Linux.不错,下次可以试试。不过它会常驻在顶部菜单栏,而我的顶部菜单栏好拥挤…

发布了227 篇原创文章 · 获赞 148 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/toopoo/article/details/104727039