Preface

Note: all examples below use dummy proxies; replace them with your own.

Proxies are set for these situations:

  • Crossing the GFW Great Firewall, abbreviated as 翻墙
  • Accessing 外网 from 内网
  • Accessing 内网镜像库 from 内网 (npm, composer, etc.)

Proxy methods

There are at least the following ways to configure a proxy:

  • Set the target proxy machine (most common)

    e.g.: http://yourProxyServer:port

  • Set a PAC file to match proxies automatically (common in browsers)

    e.g.: http://example/a.pac

Proxy address

Assume your currently available proxy is: http://yourProxyServer:port; the examples below all use this proxy.

Windows CMD proxy settings

Effective for the current CMD window:

REM 设置代理
set http_proxy=http://yourProxyServer:port
set https_proxy=http://yourProxyServer:port

REM 查看代理
echo %http_proxy%
echo %https_proxy%

REM 取消代理(留空即可)
set http_proxy=
set https_proxy=

To make it permanent, set the system environment variables http_proxy and https_proxy, then restart Windows.

Notes:

  • http_proxy and https_proxy both correspond to http://yourProxyServer:port; the latter may not have the s of https.

Linux proxy settings

Same as the Mac proxy settings below ↓

Mac proxy settings

This section only covers configuring a proxy from the command line.

Add a shortcut for setting the proxy in ~/.bash_profile or ~/.zshrc:

# shadowsocks 翻墙用,不翻墙可不用
alias proxy_ss='export all_proxy=socks5://127.0.0.1:1086; export http_proxy=http://127.0.0.1:1087; export https_proxy=https://127.0.0.1:1087'

# 其他代理
alias proxy_dev='export http_proxy=http://yourProxyServer:port; export https_proxy=http://yourProxyServer:port'

# 取消所有代理设置
alias unproxy='unset all_proxy; unset http_proxy; unset https_proxy'

After setting it up, remember to source the config file.

To use it, run in the shell (using a dev machine as an example):

# 设置代理
proxy_dev

# 取消代理
unproxy

Standalone commands:

# 临时设置代理
export http_proxy=http://yourProxyServer:port
export https_proxy=http://yourProxyServer:port

# 查看代理
echo $http_proxy
echo $https_proxy

# 取消代理
unset http_proxy
unset https_proxy

Mac Homebrew proxy settings

Same as the Mac command-line proxy settings above.

Brew 官方参考

Git proxy settings

Git

# 全局:设置 Git 访问外网(如 github)的代理
git config --global http.proxy http://yourProxyServer:port

# 全局:查看 Git 代理
git config --global --get http.proxy

# 全局:删除 Git 代理
git config --global --unset http.proxy



# ----------- 下面是针对每个项目局部的,非全局 -----------------
# 设置 Git 访问外网(如 github)的代理
git config http.proxy http://yourProxyServer:port

# 查看 Git 代理
git config --get http.proxy

# 删除 Git 代理
git config --unset http.proxy

Git username and email settings

# 设置 Git 全局:用户名、邮箱 ↓
git config --global user.name "youName"
git config --global user.email [email protected]

# 下面是针对每个 Git 项目的,非全局 ↓
git config user.email [email protected]
git config user.name "youName"

Which one to set globally and which one for the current project depends on your needs; there is no absolute rule.

npm proxy settings + registry settings

npm

In this case you need to set both: the Taobao mirror + your proxy (if any)

# ↓ 设置淘宝 npm 镜像
npm config set registry https://registry.npmmirror.com
# ↓ 若本来即可访问外网,无需下面代理设置
npm config set https-proxy http://yourProxyServer:port

Using the official npm registry

Set the proxy (if any):

npm config set proxy http://yourProxyServer:port
npm config set https-proxy http://yourProxyServer:port

How to check npm proxy and registry settings

# 查看 npm 所有设置
npm config list

# 查看代理
npm config get proxy
npm config get https-proxy

# 查看镜像
npm config get registry

# 取消代理
npm config rm proxy
npm config rm https-proxy

yarn proxy settings + registry settings

yarn

# 设置 registry 镜像
yarn config set registry https://registry.npmmirror.com

# 设置代理(若有的话)
yarn config set proxy http://yourProxyServer:port

# 查看所有设置
yarn config list

# 查看镜像设置
yarn config get registry

# 查看某个设置
yarn config get proxy

yarn global config: 用户目录/.yarnrc

Notes:

  • Sometimes the proxy still doesn’t take effect; this may be caused by a problem with the yarn.lock file — try deleting it and starting over.

nvm proxy settings

nvm

# 设置代理(永久)
nvm proxy "http://yourProxyServer:port"

# 设置代理(临时,非必须)
set http_proxy=http://yourProxyServer:port
set https_proxy=http://yourProxyServer:port

# 查看代理
nvm proxy

# 删除代理
nvm proxy "none"

Reference: https://github.com/coreybutler/nvm-windows#usage

Bower proxy settings

Bower

Create a new .bowerrc file and fill in proxy and https-proxy:

{
  "directory": "bower_components",
  "proxy": "http://yourProxyServer:port/",
  "https-proxy": "http://yourProxyServer:port/"
}

Three placement options are supported:

  • Current project: 当前目录(bower.json 的同级目录)
  • Current user’s home directory
  • System root directory (the / directory on Linux)

Reference: https://bower.io/docs/config/#placement--order

PHP Composer proxy settings

Composer

After installing Composer, Composer uses the system proxy directly (e.g., CMD on Windows); there is no proxy config file.

That is: on Windows you need to set the CMD proxy, something like

set http_proxy=yourProxyServer:port
set https_proxy=yourProxyServer:port

Only then can you run composer require packageName

If the system has these two environment variables configured, that effectively acts as Composer’s global proxy.

PhpStorm, IntelliJ IDEA, PyCharm, WebStorm, Android Studio (or other JetBrains IDEs) proxy settings

Jetbrains

File -> Settings -> Appearance & Behavior -> System Settings

-> HTTP Proxy -> Manual proxy configuration -> HTTP

-> Host name: yourProxyServer -> Port number: yourProxyPort

-> OK

Maven proxy and mirror settings

Maven

Maven’s proxy and mirror settings are fairly extensive; see 这里 for details.

Gradle proxy settings

Gradle

  • To configure for the current project:
    • Create or edit gradle.properties inside the current project
  • To configure globally:
    • Create or edit 用户目录/.gradle/gradle.properties

Add the following settings to the gradle.properties file:

systemProp.http.proxyHost=yourProxyServer
systemProp.http.proxyPort=yourPort
systemProp.https.proxyHost=yourProxyServer
systemProp.https.proxyPort=yourPort

Reference: https://docs.gradle.org/current/userguide/build_environment.html

pip Proxy Settings for Python

pip is used to install Python packages.

There are 3 ways to set a proxy for pip (pick one):

  • System environment variables

    • Just like the CMD proxy settings, then pip install yourPackage, Win ↓
    set http_proxy=http://yourProxyServer:port
    set https_proxy=http://yourProxyServer:port
  • --proxy parameter

    • pip install yourPackage --proxy http://yourProxyServer:port
  • pip.ini config file (recommended, permanent)

    • Taking Win as an example, create a new directory and file %HOME%\pip\pip.ini in your user directory, and fill in:

      [install]
      proxy=http://yourProxyServer:port
    • To check whether it worked: pip config list

Official pip documentation on setting a proxy: https://pip.pypa.io/en/stable/user_guide/#using-a-proxy-server

VS Code Proxy Settings

VSCode reads the proxy from the http_proxy and https_proxy environment variables by default.

But you can also set it manually: File -> Preference -> Settings, then paste the following code into User Settings on the right:

"http.proxy": "http://yourProxyServer:port",

Notepad++ Proxy Settings

Notepad++

Menu bar -> question mark ? on the far right -> 设置更新代理服务器 ->

  • Proxy server: yourProxyServer
  • Port: yourPort

Sublime Proxy Settings

Sublime uses the system’s PAC settings by default. If your browser can get online, Sublime basically can too.

You can also customize the proxy in the config file:

  • 菜单栏 -> Preferences -> Settings -> 在左右任意一侧填入:
"http_proxy": "http://yourProxyServer:port",
"https_proxy": "http://yourProxyServer:port",

Eclipse Proxy Settings

Ways to set a proxy for Eclipse:

  • Window -> Preferences -> General -> Network Connections -> select Manual in Active Provider on the right -> double-click HTTP on line 1 under Proxy entries 表格 -> enter yourProxyServer in Host -> enter yourPort in Port -> OK
  • Set HTTPS and SOCKS the same way

Atom Editor Proxy Settings

Atom

See the commands below:

# 设置代理
apm config set https-proxy https://yourProxyServer:port

# 查看代理
apm config get https-proxy

# 查看所有配置(显示的结果的 `userconfig` 就是配置文件所在位置)
apm config get

Reference: https://github.com/atom/apm#using-a-proxy

wget Proxy Settings

wget Win

wget Linux

Method 01 (temporary):

  • First set the proxy in Windows CMD:

    set http_proxy=http://yourProxyServer:port
    set https_proxy=http://yourProxyServer:port
  • Or the proxy in a Linux shell:

    export http_proxy=http://yourProxyServer:port
    export https_proxy=http://yourProxyServer:port
  • Then you can use the wget command directly

Method 02 (permanent, recommended!):

  • Just use the wget config file: create a new file .wgetrc in the current user’s home directory (or /etc/wgetrc on Linux):

    http-proxy = yourProxyServer:port
    https-proxy = yourProxyServer:port
    ftp-proxy = yourProxyServer:port
  • Then you can use the wget command directly

Method 03 (temporary):

  • Add parameters directly to the wget command, e.g.
    • wget https://www.baidu.com -e https-proxy=yourProxyServer:port
    • or (both are http, not https)
    • wget http://www.baidu.com -e http-proxy=yourProxyServer:port

curl Proxy Settings

curl

Method 01 (temporary):
(This is part 2 of 4 of the same post.)

  • First, set the proxy for Windows CMD:
    set http_proxy=yourProxyServer:port
    set https_proxy=yourProxyServer:port
  • Or the proxy for the Linux shell:
    export http_proxy=yourProxyServer:port
    export https_proxy=yourProxyServer:port
  • Then you can use the curl command directly, for example
    • curl http://www.baidu.com -o baidu.html

Method 02 (permanent, recommended!):

  • Just use the curl config file. Create a new config file in the current user’s home directory (Win: _curlrc) (Linux: .curlrc):
    proxy = yourProxyServer:port
  • Then you can use the curl command directly, for example
    • curl http://www.baidu.com -o baidu.html

Method 03 (temporary):

  • Add the parameter directly to the curl command, for example
    • curl https://www.baidu.com -o baidu.html -x yourProxyServer:port

      -x The lowercase x means proxy

Golang’s go get Proxy

Golang’s go get uses the system’s http_proxy, but pulling code uses Git’s proxy,
so you need to do both steps:

  1. Set the system proxy (or CMD proxy)
set http_proxy=yourProxyServer:port
  1. Set the Git proxy, see Git 代理设置 above
git config --global http.proxy http://yourProxyServer:port

References:

If you use VS Code, and want VS Code to automatically download Go’s dependency tools, you should also set the proxy in VS Code’s settings.json:

"http.proxy": "http://yourProxyServer:port",

Navicat seemingly requires configuring both 通道地址 and 代理服务器.

Note: This method is not very secure; use it with caution!

  • Step 01: In the Navicat installation directory, find the file: C:\Program Files\PremiumSoft\Navicat Premium\ntunnel_mysql.php (or the php for the corresponding language), and place it in your external web service directory (open http://IP:port/abc/ntunnel_mysql.php in a browser and you should see a page)
  • Step 02: 右键某个数据库连接 -> HTTP -> check 使用 HTTP 通道 -> fill in http://IP:port/abc/ntunnel_mysql.php for 通道地址 -> below 代理服务器 -> check 使用代理服务器 -> fill in yourPorxyServer for 主机 -> fill in yourPort for 端口 -> 测试连接 -> 确定

VirtualBox and VMware Proxy Settings

Most users run their VMs in NAT mode.

Proxy settings: the system inside the VM must use the same proxy settings as the host physical machine in order to get online.

Xshell Proxy Settings

Open the properties of a session

  • Connection
  • Proxy
  • Browse
  • Add
    • Name: anyName (or any name you like)
    • Type: HTTP 1.1
    • Host: yourProxyServer
    • Port: yourPort
    • OK
    • Close
  • For Proxy Server, select the proxy you just created
  • Done

SecureCRT Proxy Settings

Two steps: first add a global proxy entry, then select the corresponding proxy entry in each connection.

  1. Add a global proxy entry
  • Options
  • Global Options
  • Firewall
    • Add
      • Name: anyName (or any name you like)
      • Type: HTTP (no authentication)
      • Hostname or IP: yourProxyServer
      • Port: yourPort
      • OK
  1. Select the newly created proxy entry in your connection
  • Your connection -> Properties
  • Connection
  • SSH2
  • Firewall
  • Select 刚新建的代理项

Proxifier: Setting Up a Proxy for Other Software

Proxifier

Unlike the previous software, where each sets its own proxy, Proxifier takes a different approach: it sets up a proxy for other software uniformly.

Advantages:

  • No need to configure proxies separately for each app in its own way
  • Apps without a proxy settings UI work well with Proxifier
  • You can see the actual traffic of the proxied apps
  • Works on both Windows and Mac

Drawbacks:

  • Proxy settings aren’t always granular enough (e.g., Git’s global proxy vs. the proxy for the current Git project)

Steps:

  1. 菜单栏 Profile -> Proxy Servers -> Add -> Address, enter yourProxyServer -> Port, enter yourPort -> Protocol, enter HTTPS -> OK
  2. 菜单栏 Profile -> Proxification Rules -> Add -> Name, fill in anything - > Applications select the exe file of the app you want to proxy via the Browse button -> Action choose the yourProxyServer set in the previous steps -> OK

Credits

Thanks to Dylan for the proxy roundup!

This article is reposted from: dylan-7/note/blob/main/常用代理设置汇总.md