在需經由 Proxy 存取外網的環境中,wget 預設不使用 Proxy,需顯式設定。本文提供三種設定方式,涵蓋單次指令、當前 Shell 會話、永久生效三個層級,並區分 HTTP/HTTPS 協定差異。

# HTTP
wget https://example.com/file -e use_proxy=yes -e http_proxy=proxy.host:3128
# HTTPS (需額外參數)
wget --no-check-certificate https://example.com/file \
-e use_proxy=yes -e https_proxy=proxy.host:3128
--no-check-certificate:跳過 SSL 憑證驗證(測試環境常用,生產慎用)。https_proxy 參數專門處理 HTTPS 請求,不可混用 http_proxy。export http_proxy=https://proxy.host:3128
export https_proxy=https://proxy.host:3128
# 或帶認證
export http_proxy=https://user:pass@proxy.host:3128
# 取消 Proxy
unset http_proxy https_proxy
wget、curl、apt、yum、git、pip 等皆自動使用。~/.bashrc 或 /etc/profile 可永久生效。~/.wgetrc 配置檔(wget 專用、永久生效)cat > ~/.wgetrc <<'EOF'
http_proxy = https://proxy.host:3128/
https_proxy = https://proxy.host:3128/
ftp_proxy = https://proxy.host:3128/
use_proxy = on
wait = 15
EOF
.wgetrc > 系統預設。/etc/wgetrc(影響所有用戶)。| 情況 | 指令/設定 |
|---|---|
| 單次指令強制不使用 Proxy | wget --no-proxy https://example.com |
| Proxy 需認證(帳號密碼含特殊字元) | http_proxy=https://user%40domain:pass%23word@proxy.host:3128 (URL 編碼) |
| SOCKS5 Proxy | export http_proxy=socks5://proxy.host:1080 (wget 1.18+ 支援) |
| 透明 Proxy/攔截式 (無需客戶端設定) | 無需設定,網路層自動導流 |
wget -q -O - https://httpbin.org/ip
# 輸出應為 Proxy 出口 IP,而非本機公網 IP
依據使用場景選擇方式:腳本自動化用環境變數、單次下載用命令列參數、個人習慣用 .wgetrc,三種方式靈活組合。
Linux 磁碟空間清理實戰指南:find 尋找大檔/空檔/舊檔、rpm 套件管理、inode 監控、du 目錄分析完整工具箱
Linux 多網卡重新命名實戰:修改模組別名、配置檔與模組重載
Linux alias 指令別名設定:顯示/建立/移除、寫入啟動檔永久生效、限定用戶權限
Linux nl 指令完整教學:行號顯示、空行處理、格式化輸出與實戰範例
Linux 瀏覽器 HTTPS 頁面阻擋 HTTP 混合內容警報:CSP upgrade-insecure-requests 部署指南
Linux 製作可開機 IMG/ISO 鏡像完整教學:dd、mkisofs、grub4dos 實戰