Tianhe Gao

Proxy

Concept

PAC(proxy auto-config)

https://en.wikipedia.org/wiki/Proxy_auto-config 根据给定访问地址,自动选择代理服务器

Set up a proxy for these software

Shell

1export http_proxy=http://127.0.0.1:1080
2export https_proxy=http://127.0.0.1:1080
3
4export http_proxy_user=user
5export http_proxy_pass=pass
6
7export https_proxy_user=user
8export https_proxy_pass=pass

pip

~/.config/pip/pip.conf

[global]
proxy=http://localhost:1087

注意不支持socks5

refer https://pip.pypa.io/en/stable/user_guide/#using-a-proxy-server

Git

  1. Clone with ssh

    在文件 ~/.ssh/config 后添加下面两行:

    1Host github.com
    2# Mac下
    3ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
    4# Linux下
    5ProxyCommand nc --proxy-type socks5 --proxy 127.0.0.1:1080 %h %p

    注意 Linux 和 Mac 下 ncat/netcat 区别,详见 https://unix.stackexchange.com/q/368155

  2. Clone with http

    1git config --global http.proxy http://127.0.0.1:1087

    建议使用 http,因为 Socks5 在使用 git-lfs 时会报错 proxyconnect tcp: dial tcp: lookup socks5: no such host

    refer https://gist.github.com/laispace/666dd7b27e9116faece6

cargo

Cargo 会依次检查以下位置

  1. 环境变量 CARGO_HTTP_PROXY
1export CARGO_HTTP_PROXY=http://127.0.0.1:1080
  1. 任意 config.toml 中的 http.proxy
1[http]
2proxy = "127.0.0.1:1080"
  1. 环境变量 HTTPS_PROXY & https_proxy & http_proxy
1export https_proxy=http://127.0.0.1:1080
2export http_proxy=http://127.0.0.1:1080

http_proxy 一般来讲没必要,除非使用基于 HTTP 的 Crate Repository

Cargo 使用 libcurl,故可接受任何符合 libcurl format 的地址与协议

( 127.0.0.1:1080 , http://127.0.0.1:1080 , socks5://127.0.0.1:1080 )均可

refer https://doc.rust-lang.org/cargo/reference/config.html#httpproxy

apt (apt-get)

/etc/apt/apt.conf.d/ 目录下新增 proxy.conf 文件,加入:

Acquire::http::Proxy "http://127.0.0.1:8080/";
Acquire::https::Proxy "http://127.0.0.1:8080/";

注:无法使用 Socks5 代理。

refer https://askubuntu.com/a/349765/883355

curl

1socks5 = "127.0.0.1:1080"

add to ~/.curlrc

refer https://www.zhihu.com/question/31360766

Gradle

=~/.gradle/gradle.properties=:

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1087
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1087

refer https://stackoverflow.com/q/5991194/12539782

Maven

=%Maven 安装目录%/conf/settings.xml=:

<!-- proxies
 | This is a list of proxies which can be used on this machine to connect to the network.
 | Unless otherwise specified (by system property or command-line switch), the first proxy
 | specification in this list marked as active will be used.
 |-->
<proxies>
  <!-- proxy
   | Specification for one proxy, to be used in connecting to the network.
   |
  <proxy>
    <id>optional</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>proxyuser</username>
    <password>proxypass</password>
    <host>proxy.host.net</host>
    <port>80</port>
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
  </proxy>
  -->
   <proxy>
    <id>proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>127.0.0.1</host>
    <port>1087</port>
  </proxy>
</proxies>

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

go get

1HTTP_PROXY=socks5://localhost:1080 go get

测试了下 HTTPS_PROXYALL_PROXY 都不起作用

OR 使用goproxy.io

npm

1npm config set proxy http://127.0.0.1:1087
2npm config set https-proxy http://127.0.0.1:1087

用 Socks5 就报错- -

推荐使用 yarn,npm 是真的慢

refer https://stackoverflow.com/q/7559648/12539782

yarn

1yarn config set proxy http://XX
2yarn config set https-proxy http://XX

不支持 socks5

refer https://github.com/yarnpkg/yarn/issues/3418

rustup

1export https_proxy=http://127.0.0.1:1080

gem

=~/.gemrc=:

---
# See 'gem help env' for additional options.
http_proxy: http://localhost:1087

brew

ALL_PROXY=socks5://localhost:1080 brew ...

wget

=~/.wgetrc=:

use_proxy=yes
http_proxy=127.0.0.1:1087
https_proxy=127.0.0.1:1087

refer https://stackoverflow.com/q/11211705/12539782

snap

1sudo snap set system proxy.http="http://127.0.0.1:1087"
2sudo snap set system proxy.https="http://127.0.0.1:1087"

refer https://snapcraft.io/docs/system-options

docker

1sudo mkdir -p /etc/systemd/system/docker.service.d
2sudo vim /etc/systemd/system/docker.service.d/proxy.conf
[Service]
Environment="ALL_PROXY=socks5://localhost:1080"
1sudo systemctl daemon-reload
2sudo systemctl restart docker

必须是 Socks5,http 不生效

refer

  1. https://docs.docker.com/network/proxy/
  2. https://elegantinfrastructure.com/docker/ultimate-guide-to-docker-http-proxy-configuration/

Electron Dev Dependency

Tools for Proxy

Clash

v2ray-core

ssrlocal, sslocal


No notes link to this note