Preface
Note: all examples below use dummy proxies; replace them with your own.
Proxies are set for these situations:
- Crossing the
GFWGreat 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:portSet 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_proxyandhttps_proxyboth correspond tohttp://yourProxyServer:port; the latter may not have thesofhttps.
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
# 取消代理
unproxyStandalone commands:
# 临时设置代理
export http_proxy=http://yourProxyServer:port
export https_proxy=http://yourProxyServer:port
# 查看代理
echo $http_proxy
echo $https_proxy
# 取消代理
unset http_proxy
unset https_proxyMac Homebrew proxy settings
Same as the Mac command-line proxy settings above.
Git proxy settings
# 全局:设置 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.proxyGit 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
Using the Taobao npm mirror (recommended)
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:portUsing the official npm registry
Set the proxy (if any):
npm config set proxy http://yourProxyServer:port
npm config set https-proxy http://yourProxyServer:portHow 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-proxyyarn proxy settings + registry settings
# 设置 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 proxyyarn global config: 用户目录/.yarnrc
Notes:
Sometimes the proxy still doesn’t take effect; this may be caused by a problem with the
yarn.lockfile — try deleting it and starting over.Reference: yarnpkg/yarn#4890
nvm proxy settings
# 设置代理(永久)
nvm proxy "http://yourProxyServer:port"
# 设置代理(临时,非必须)
set http_proxy=http://yourProxyServer:port
set https_proxy=http://yourProxyServer:port
# 查看代理
nvm proxy
# 删除代理
nvm proxy "none"Bower proxy settings
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)
PHP Composer proxy settings
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:portOnly 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
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’s proxy and mirror settings are fairly extensive; see 这里 for details.
Gradle proxy settings
- To configure for the current project:
- Create or edit
gradle.propertiesinside the current project
- Create or edit
- To configure globally:
- Create or edit
用户目录/.gradle/gradle.properties
- Create or edit
Add the following settings to the gradle.properties file:
systemProp.http.proxyHost=yourProxyServer
systemProp.http.proxyPort=yourPort
systemProp.https.proxyHost=yourProxyServer
systemProp.https.proxyPort=yourPortReference: 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- Just like the CMD proxy settings, then
--proxyparameterpip install yourPackage --proxy http://yourProxyServer:port
pip.iniconfig file (recommended, permanent)Taking Win as an example, create a new directory and file
%HOME%\pip\pip.iniin your user directory, and fill in:[install] proxy=http://yourProxyServer:portTo 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
Menu bar -> question mark ? on the far right -> 设置更新代理服务器 ->
Proxy server: yourProxyServerPort: 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-> selectManualinActive Provideron the right -> double-clickHTTPon line 1 underProxy entries 表格-> enteryourProxyServerinHost-> enteryourPortinPort->OK- Set
HTTPSandSOCKSthe same way
Atom Editor Proxy Settings
See the commands below:
# 设置代理
apm config set https-proxy https://yourProxyServer:port
# 查看代理
apm config get https-proxy
# 查看所有配置(显示的结果的 `userconfig` 就是配置文件所在位置)
apm config getReference: https://github.com/atom/apm#using-a-proxy
wget Proxy Settings
Method 01 (temporary):
First set the proxy in Windows CMD:
set http_proxy=http://yourProxyServer:port set https_proxy=http://yourProxyServer:portOr the proxy in a Linux shell:
export http_proxy=http://yourProxyServer:port export https_proxy=http://yourProxyServer:portThen you can use the wget command directly
Method 02 (permanent, recommended!):
Just use the wget config file: create a new file
.wgetrcin the current user’s home directory (or/etc/wgetrcon Linux):http-proxy = yourProxyServer:port https-proxy = yourProxyServer:port ftp-proxy = yourProxyServer:portThen 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
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-xThe lowercase x meansproxy
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:
- Set the system proxy (or CMD proxy)
set http_proxy=yourProxyServer:port- Set the Git proxy, see
Git 代理设置above
git config --global http.proxy http://yourProxyServer:portReferences:
- https://stackoverflow.com/a/10385612/2752670
- Official reference: https://github.com/golang/go/wiki/GoGetProxyConfig
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 Connecting to an External Database
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 (openhttp://IP:port/abc/ntunnel_mysql.phpin a browser and you should see a page) - Step 02:
右键某个数据库连接->HTTP-> check使用 HTTP 通道-> fill inhttp://IP:port/abc/ntunnel_mysql.phpfor通道地址-> below代理服务器-> check使用代理服务器-> fill inyourPorxyServerfor主机-> fill inyourPortfor端口->测试连接->确定
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.
- 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
- Add
- Select the newly created proxy entry in your connection
- Your connection -> Properties
- Connection
- SSH2
- Firewall
- Select
刚新建的代理项
Proxifier: Setting Up a Proxy for Other Software
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:
菜单栏 Profile->Proxy Servers->Add->Address, enteryourProxyServer->Port, enteryourPort->Protocol, enterHTTPS->OK菜单栏 Profile->Proxification Rules->Add->Name, fill in anything - >Applicationsselect the exe file of the app you want to proxy via theBrowsebutton ->Actionchoose theyourProxyServerset in the previous steps ->OK
Credits
Thanks to Dylan for the proxy roundup!
This article is reposted from: dylan-7/note/blob/main/常用代理设置汇总.md
