Convert socks5 to http proxy

2019-05-08  本文已影响0人  路过麦田

安装

sudo apt-get install polipo

sudo service polipo stop

设置

# 快速运行
sudo polipo socksParentProxy=localhost:1080

# 使用配置文件

sudo vi /etc/polipo/config

# 输入下面内容

socksParentProxy = “127.0.0.1:1080″
socksProxyType = socks5
proxyAddress = "::0"        # both IPv4 and IPv6
# or IPv4 only
# proxyAddress = "0.0.0.0"
proxyPort = 8123


运行:

$ sudo polipo -c /etc/polipo/config

使用

# http/https
http_proxy=http://localhost:8123 apt-get update
http_proxy=http://localhost:8123 curl www.google.com
http_proxy=http://localhost:8123 wget www.google.com

https_proxy=http://localhost:8123 wget https://google.com

# ftp
ftp_proxy=http://localhost:8123 

# git
git config --global http.proxy 127.0.0.1:8123
git clone https://github.com/xxx/xxx.git
git xxx
git xxx
git config --global --unset-all http.proxy

# gradle
gradlew -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080
gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8123
gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8123
gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8123 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8123

解决android studio中Gradle Sync操作卡住的问题

在同步的时候经常会出现卡在访问dl.google.com的时候,例如:

Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.3.2/gradle-3.3.2.pom'

对于自定义的maven也经常会出现这个问题,忽略自定义的maven服务器,直接访问google的服务器,针对这个问题,可以在命令行中执行同步的命令,因为非命令行同步时不容易指定参数,肯定是通过不了的

还有一种方式是采用Offline work,将该选项打勾,每次都从缓存中读取,也勉强能用,但是一旦依赖库有更新时,还是会遇到这个问题

下面记录一下目前可以使用的解决方案:

./gradlew --refresh-dependencies --info -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8123 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8123

# 或者

./gradlew --refresh-dependencies --info -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080

# --refresh-dependencies 更新依赖项
# --info 显示执行过程
# --stacktrace 显示堆栈信息

开机启动

# 编写polipo.service
sudo vi /etc/systemd/system/polipo.service

[Unit]
Description=polipo service
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/polipo -c /etc/polipo/config

[Install]
WantedBy=multi-user.target

# 使polipo.service生效
sudo systemctl daemon-reload
sudo systemctl start polipo.service

# 写入环境变量

vi ~/.bashrc

# 添加下面代码

export http_proxy=http://localhost:8123
export https_proxy=http://localhost:8123

# 保存后执行

source ~/.bashrc # 使环境变量生效

上一篇 下一篇

猜你喜欢

热点阅读