mac命令终端配置代理

2,114 阅读2分钟

1.测试当前环境

curl ip.gs

2.安装polipo

brew install polipo

3.启动

a.启动监听

polipo socksParentProxy=127.0.0.1:1080

b.创建每次系统启动都监听

1.创建启动文件
ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents  
2.编辑启动文件设置parentProxy
vim /usr/local/opt/polipo/homebrew.mxcl.polipo.plist
<?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>
    <key>SoftResourceLimits</key>
    <dict>
        <key>NumberOfFiles</key>
        <integer>65536</integer>
    </dict>
</dict>
</plist>
3.全局配置环境
vim ~/.bash_profile

增加以下代码用来控制代理开启和关闭

# -------------------------------
# polipo proxy on/off
# ------------------------------
function proxy_off() {
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
    unset http_proxy
    unset https_proxy
    git config --global --unset http.proxy
    git config --global --unset https.proxy
}

function proxy_on() {
   export http_proxy=http://localhost:8123
   export https_proxy=https://localhost:8123
   git config --global http.proxy 'socks5://127.0.0.1:1080'
   git config --global https.proxy 'socks5://127.0.0.1:1080'
   launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
}
4.使用

在某个命令终端启动,其他命令终端不受影响

启动: proxy_on
关闭:proxy_off

4.遇到Git配置问题

a.git 移除全局配置代理

git config --global --unset http.proxy
git config --global --unset https.proxy

b.查看信息git配置信息

git config --global -l 

c.设置代理

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

如果配置了全局的git会影响到sourcetree或者其他命令终端的git命令,请使用移除git全局命令先移除代理配置!!!

mac下载webrtc遇到问题: NOTICE: You have PROXY values set in your environment, but gsutil in depot_tools does not (yet) obey them. Also, --no_auth prevents the normal BOTO_CONFIG environment variable from being used. To use a proxy in this situation, please supply those settings in a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environment var. 解决方案:

1.在depot_tools文件夹下创建https_proxy.boto文件,文件内容
[Boto]
proxy = localhost
proxy_port = 8123
2.配置环境变量在.bash_profile
export NO_AUTH_BOTO_CONFIG=/Users/Crassus/Desktop/project/YST/WebRTCSource/depot_tools/https_proxy.boto

总的配置

# -------------------------------
# polipo current seession
# -------------------------------
function proxy_off() {
    unset http_proxy
    unset https_proxy
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    echo -e "已关闭代理"
}

function proxy_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:1087"
    export https_proxy=$http_proxy
    git config --global http.proxy 'socks5://127.0.0.1:1086'
    git config --global https.proxy 'socks5://127.0.0.1:1086'
    echo -e "已开启代理"
}

验证是否成功

curl cip.cc