Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Unix/Linux 環境下配置 HTTP/HTTPS/FTP 代理全攻略:環境變量、wget、curl、apt、git、Docker

編輯:Linux 系統常見問題解答

獲取代理地址

  • IE/瀏覽器網絡設置 → 查看代理 IP:Port。
  • PAC 腳本自動配置:netstat -an 觀察瀏覽器連接目標 IP:Port,高頻出現即為代理。

Shell 環境變量 (通用)

export http_proxy=https://proxy_ip:port/export https_proxy=https://proxy_ip:port/export ftp_proxy=ftp://proxy_ip:port/export no_proxy="localhost,127.0.0.1,::1,.internal.corp"  # 繞過代理# 帶認證export http_proxy=https://user:pass@proxy_ip:port/  # 特殊字符需 URL 編碼

持久化:寫入 ~/.bashrc / /etc/profile.d/proxy.sh。

常用工具獨立配置

工具配置方式
wgetwget --proxy-user=USER --proxy-password=PASS URL 或 wget --no-proxy URL 繞過
curlcurl -x https://proxy_ip:port URL (HTTP/HTTPS)
curl --socks4 proxy_ip:port URL
curl --socks5 proxy_ip:port URL
curl -U user:pass URL (使用環境變量代理)
curl --noproxy URL 繞過
aptecho 'Acquire::http::Proxy "https://proxy_ip:port/";' > /etc/apt/apt.conf.d/99proxy
yum/dnfproxy=https://proxy_ip:port/ 寫入 /etc/yum.conf [main] 區段
gitgit config --global http.proxy https://proxy_ip:port
git config --global https.proxy https://proxy_ip:port
git config --global --unset http.proxy 取消
npmnpm config set proxy https://proxy_ip:port
npm config set https-proxy https://proxy_ip:port
pippip install --proxy https://proxy_ip:port package
Docker (daemon)/etc/systemd/system/docker.service.d/http-proxy.conf:
[Service]
Environment="HTTP_PROXY=https://proxy_ip:port/"
Environment="HTTPS_PROXY=https://proxy_ip:port/"
Environment="NO_PROXY=localhost,127.0.0.1,.internal.corp"
然後 systemctl daemon-reload && systemctl restart docker
Docker (build)docker build --build-arg HTTP_PROXY=... --build-arg HTTPS_PROXY=... .
SSH 穿透代理ProxyCommand nc -X connect -x proxy_ip:port %h %p (需 netcat-openbsd)

桌面環境

Firefox/Chrome:設置 → 網絡 → 代理 → 手動配置 HTTP/HTTPS/SOCKS。GNOME/KDE 系統設置 → 網絡 → 網絡代理 → 同步到環境變量。

驗證

curl -I https://www.google.com  # 通過代理返回環境變量 IPenv | grep -i proxy          # 檢查變量生效
Copyright © Windows教程網 All Rights Reserved