Developer 最常用的 Proxy 設定
本文整理了系統環境變數、 git、curl、wget、npm、bundler、nuget、brew、apt 與 chocolatey 等多種下載工具的 proxy 設定。
前言
當公司有做網路控管時,對外的網路請求通常需要經由 proxy server 轉送,對內或 localhost 的可以不需要,要也沒關係就是要繞一圈比較慢。
接下來我們將用 http://proxy.company.com:80 這個 proxy server 為例,示範如何設置其他工具的 proxy。
系統環境變數 environment
Windows
控制台 > 系統及安全性 > 系統 > 進階系統設定 > 進階 > 環境變數 > 系統變數 > 新增
| 變數 | 值 |
|---|---|
| PROXY | http://proxy.company.com:80 |
| HTTP_PROXY | http://proxy.company.com:80 |
| HTTPS_PROXY | http://proxy.company.com:80 |
| ALL_PROXY | http://proxy.company.com:80 |
| NO_PROXY | localhost,127.0.0.1,.company.com |
| proxy | http://proxy.company.com:80 |
| http_proxy | http://proxy.company.com:80 |
| https_proxy | http://proxy.company.com:80 |
| all_proxy | http://proxy.company.com:80 |
| no_proxy | localhost,127.0.0.1,.company.com |
Ubuntu
在 ~/.profile 中新增
1 | PROXY="http://proxy.company.com:80" |
確保你使用的 shell,如 zsh,會在登入後 source ~/.profile
git
下指令
1 | git config --global http.proxy http://proxy.company.com:80 |
或是編輯 .gitconfig,位於
- Linux :
~/.gitconfig - Windows :
%USERPROFILE%\.gitconfig
填入
1 | [http] |
curl
建議使用環境變數設定 curl,它預設會套用環境變數,見官方文件
或是編輯 .curlrc,位於
- Windows
%APPDATA%\_curlrc%USERPROFILE%\Application Data\_curlrc
- Linux
~/.curlrc
填入
1 | https_proxy=http://proxy.company.com:80 |
wget
建議使用環境變數設定 wget,它預設會套用環境變數,見官方文件
或是編輯 .wgetrc,填入
1 | use_proxy = on |
npm
透過指令
1 | npm config set https-proxy http://proxy.company.com:80 |
或是編輯 .npmrc,位於
- Windows :
%USERPROFILE%\.npmrc - Linux :
~/.npmrc
bundler
建議使用環境變數設定 bundler,它預設會套用環境變數,見官方文件
或是編輯 gemrc,設定檔位於 ~/.gemrc,填入
1 |
|
nuget
建議使用環境變數設定 nuget,它預設會套用環境變數,見官方文件
透過命令列 or 編輯設定檔
1 | nuget config -set http_proxy=http://proxy.company.com:80 |
設定檔位於
- Windows
%APPDATA%\NuGet\NuGet.Config%USERPROFILE%\.nuget
- Linux
~/.nuget
填入
1 | <configuration> |
brew
使用 curl 來取得軟體,因此需要設定的是 curl
apt
建議使用環境變數設定 apt,它預設會套用環境變數,見官方文件
如需編輯設定檔,可至 /etc/apt/apt.conf,填入
1 | Acquire::http::proxy "http://proxy.company.com:80"; |
注意!apt 會以環境變數 http_proxy 設定優先,所以當你有設定 http_proxy 後,apt.conf 內的設定就會被無視。
chocolatey
建議使用環境變數設定 chocolatey,它預設會套用環境變數,見官方文件
透過指令設定 proxy
1 | choco config set proxy http://proxy.company.com:80 |
Developer 最常用的 Proxy 設定
https://blog.yang-hong-xin.com/the-most-common-proxy-settings-for-developers/



