Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

為 wget 設定 HTTP/HTTPS 代理下載

下載公開資源時 wget 不用任何設定,但要走代理就得明確告訴它。以下整理兩種方式:臨時帶參數,或寫進設定檔長期有效。

為 wget 設定 HTTP/HTTPS 代理下載

方式一:命令列帶參數

HTTP 下載:

wget https://www.baidu.com/ -e use_proxy=yes -e http_proxy=yourproxy.com:port

HTTPS 還要多一個參數,且必須用 https_proxy(不是 http_proxy):

wget --no-check-certificate https://www.google.com/ \

  -e use_proxy=yes -e https_proxy=yourproxy.com:port

--no-check-certificate 會跳過伺服器憑證檢查,僅適用於內部或測試環境,對外連線請保留憑證驗證。

若不想每次都帶參數,可直接在 shell 中匯出環境變數,之後所有支援代理的程式都會沿用:

export http_proxy=yourproxy.com:port
export https_proxy=yourproxy.com:port

臨時要停用代理時,加上 --no-proxy 即可。

方式二:寫入設定檔

編輯 ~/.wgetrc:

http_proxy = https://ip_or_domainname:80/
ftp_proxy = https://ip_or_domainname:80/
use_proxy = on
wait = 15

之後直接 wget https://ip/filename 就會走代理。wait = 15 的作用是每次請求間隔 15 秒,避免對伺服器造成壓力。

選擇很簡單:偶爾用一次就帶參數,長期在該環境工作就寫進 .wgetrc。若代理需要帳密,格式為 https://user:pass@host:port,但明文密碼會留在 .wgetrc 與 shell 歷史紀錄中,建議改用 ~/.netrc 並設為 600 權限。

Copyright © Linux教程網 All Rights Reserved