Skip to content

为 wget / NPM / Gradle ... 设置代理 #76

@techiall

Description

@techiall

假设 socks 代理地址为 127.0.0.1:1080,即 socks5://127.0.0.1:1080

假设 http 代理地址为 127.0.0.1:1081,即 http://127.0.0.1:1081


Git

参考:https://gist.github.com/laispace/666dd7b27e9116faece6

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

但是这种方法只对 http 协议有用,对 SSH 没用。

~/.ssh/config 写入以下内容即可,记得安装 nc

ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

Windows 请使用以下配置,用 git bash 打开 ~/.ssh/config ,并写入以下内容

ProxyCommand connect -S 127.0.0.1:1080 %h %p

Wget

参考:https://stackoverflow.com/questions/11211705/how-to-set-proxy-for-wget

/etc/wgetrc 或者 ~/.wgetrc 创建一个文件,并写入以下内容

use_proxy=yes
http_proxy=127.0.0.1:1081
https_proxy=127.0.0.1:1081

Gradle

参考:https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy

在项目根目录,创建一个 gradle.properties 文件,写入以下内容。

#http proxy setup
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1081
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

#https proxy setup
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1081
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

Maven

参考:https://maven.apache.org/guides/mini/guide-proxies.html

https://stackoverflow.com/questions/1251192/how-do-i-use-maven-through-a-proxy

maven 设置 proxy 比较麻烦,得在 ~/.m2/settings.xml 里面配置,加入以下设置。

<settings>
  <proxies>
   <proxy>
      <id>http-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>1081</port>
    </proxy>
    <proxy>
      <id>https-proxy</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>127.0.0.1</host>
      <port>1081</port>
    </proxy>
  </proxies>
</settings>

NPM

npm config set proxy http://127.0.0.1:1081
npm config set https-proxy http://127.0.0.1:1081

yarn

yarn config set proxy http://127.0.0.1:1081
yarn config set https-proxy http://127.0.0.1:1081

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions