techiall / Blog

🍋 [My Blog] See discussions
https://github.com/techiall/Blog/discussions
MIT License
8 stars 1 forks source link

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

Closed techiall closed 2 years ago

techiall commented 3 years ago

假设 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
techiall commented 3 years ago

NPM 取消自定义配置

Windows,当前用户目录,找到 .npmrc,删除该文件,即可恢复默认设置

Linux / macOS,rm -rf ~/.npmrc,执行改命令即可

yarn 取消自定义配置

Windows,当前用户目录,找到 .yarnrc,删除该文件,即可恢复默认设置

Linux / macOS,rm -rf ~/.yarnrc,执行该命令即可

techiall commented 3 years ago

yum 设置代理

参考链接:https://docs.fedoraproject.org/en-US/Fedora_Core/3/html/Software_Management_Guide/sn-yum-proxy-server.html

export http_proxy=http://127.0.0.1:1081
export https_prox=http://127.0.0.1:1081
techiall commented 3 years ago

DNF 设置代理

Fedora DNF

参考连接:https://computingforgeeks.com/configure-system-wide-proxy-settings-on-centos-rhel-fedora/

sudo vim /etc/dnf/dnf.conf

# Add
proxy=http://127.0.0.1:1081