通过 /etc/wgetrc
对系统的所有用户或仅通过 ~/.wgetrc
文件的用户:
use_proxy=yes
http_proxy=127.0.0.1:8080
https_proxy=127.0.0.1:8080
或通过 URL 后面的 -e
选项:
wget ... -e use_proxy=yes -e http_proxy=127.0.0.1:8080 ...
输入命令行:
$ export http_proxy=http://proxy_host:proxy_port
对于经过身份验证的代理,
$ export http_proxy=http://username:password@proxy_host:proxy_port
然后运行
$ wget fileurl
对于 https,只需使用 https_proxy 而不是 http_proxy。您也可以将这些行放在您的 ~/.bashrc 文件中,这样您就不需要每次都执行此操作。
$ wget --version GNU Wget 1.14 built on linux-gnu. +digest +https +ipv6 +iri +large-file +nls +ntlm +opie +ssl/openssl
以下可能的配置位于 /etc/wgetrc
中,只需取消注释并使用...
# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
# If you do not want to use proxy at all, set this to off.
#use_proxy = on
wget 在命令行中使用类似这样的环境变量可以工作:
export http_proxy=http://your_ip_proxy:port/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export dns_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
在尝试了许多教程来在经过身份验证的代理后面配置我的 Ubuntu 16.04 LTS 之后,它使用了以下步骤:
编辑 /etc/wgetrc
:
$ sudo nano /etc/wgetrc
取消注释这些行:
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
#use_proxy = on
将 http://proxy.yoyodyne.com:18023/
更改为 http://username:password@domain:port/
重要提示:如果仍然无效,请检查您的密码是否包含特殊字符,例如 #、@、... 如果是这种情况,请将它们转义(例如,将 passw@rd 替换为 passw%40rd)。
在 Ubuntu 12.x 中,我在 $HOME/.wgetrc 中添加了以下行
http_proxy = http://uname:passwd@proxy.blah.com:8080 use_proxy = on
如果您只需要使用代理执行一次 wget,最简单的方法是使用这样的单行代码:
http_proxy=http://username:password@proxy_host:proxy_port wget http://fileurl
或使用 https 目标 URL:
https_proxy=http://username:password@proxy_host:proxy_port wget https://fileurl
在 Debian Linux 中,可以通过环境变量和 wgetrc 将 wget 配置为使用代理。在这两种情况下,用于 HTTP 和 HTTPS 连接的变量名称都是
http_proxy=hostname_or_IP:portNumber
https_proxy=hostname_or_IP:portNumber
请注意,文件 /etc/wgetrc 优先于环境变量,因此如果您的系统在那里配置了代理并且您尝试使用环境变量,它们似乎没有效果!
在我的 ubuntu 中,遵循 $HOME/.wgetrc 中的行就可以了!
http_proxy = http://uname:passwd@proxy.blah.com:8080 use_proxy = on
export http_proxy=http://proxy_host:proxy_port/
export https_proxy=https://proxy_host:proxy_port/
或者
export http_proxy=http://username:password@proxy_host:proxy_port/
export https_proxy=https://username:password@proxy_host:proxy_port/
正如所有其他人在这里解释的那样,这些环境变量有助于传递代理。
注意:但请注意,如果密码包含任何特殊字符,则需要将其配置为 %<hex_value_of_special_char>
。
示例:如果密码为pass#123
,则需要在上述导出命令中用作pass%23123
。
在 Windows 中——对于 Fiddler 来说——使用环境变量:
set http_proxy=http://127.0.0.1:8888
set https_proxy=http://127.0.0.1:8888
在文件 ~/.wgetrc 或 /etc/wgetrc 中添加以下行(如果文件不存在则创建该文件):
http_proxy = http://[Proxy_Server]:[port]
https_proxy = http://[Proxy_Server]:[port]
ftp_proxy = http://[Proxy_Server]:[port]
如需更多信息,https://www.thegeekdiary.com/how-to-use-wget-to-download-file-via-proxy/
使用 tsocks 通过 socks5 代理启动 wget:
安装 tsocks:sudo apt install tsocks config tsocks # vi /etc/tsocks.conf server = 127.0.0.1 server_type = 5 server_port = 1080 开始:tsocks wget http://url_to_get
不定期副业成功案例分享
use_proxy=on
,而不是use_proxy=yes
。否则效果很好。on
或off
,但实际上尝试了一个虚假命令:-e use_proxy=bnw
给出wget: use_proxy: Invalid boolean ‘bnw’; use 'on' or 'off'.
而=yes
没有给出这样的错误,所以它似乎被非正式地允许。http_proxy=http://<user>:<password>@127.0.01:8080
等等。否则,您可能必须在调用 wget 时明确地提供这些(参考 - askubuntu.com/a/429943/350255)wget --no-proxy