跳到正文

wget 怎么设置代理:环境变量、.wgetrc 和密码

让 wget 通过代理下载:要设哪些变量、怎么传账号和密码、启动文件、不走代理的地址、怎么关掉,以及怎么确认真的在用。

代理改变什么,不改变什么

代理只改变你的电脑到下载服务器之间的网络路径,不改变你请求的地址,也不改变所下载网站的规则。本文讲 wget 命令;整个系统用代理请看 Linux 代理指南,curl 命令请看 curl 指南。

环境变量:标准做法

GNU Wget 手册把环境变量称为告诉 Wget 代理在哪里的标准方式。http_proxy 和 https_proxy 分别放 HTTP 和 HTTPS 连接所用代理的 URL,no_proxy 放一串逗号分隔、不应使用代理的域名后缀。变量只在你设置它的那个终端窗口里有效。Windows PowerShell 里不用 export,写成 $env:https_proxy = "..."。

为当前终端设置代理:示例

export http_proxy=http://USERNAME:PASSWORD@HOST:PORT/
export https_proxy=http://USERNAME:PASSWORD@HOST:PORT/
wget https://example.com/file.zip

请把 HOST、PORT、USERNAME 和 PASSWORD 换成「我的资产」里的值。

账号和密码

手册给了两种办法。一是把账号和密码写进代理 URL,比如 http://hniksic:[email protected]:8001/。二是用 --proxy-user 和 --proxy-password 选项(在启动文件里是 proxy_user 和 proxy_password);Wget 会用 basic 认证方式对它们编码,手册说代理认证目前只实现了这一种。手册在讲 URL 的一节说,不安全的字符可以写成 %xy,并列出 %(%25)、:(%3A)和 @(%40);所以密码里有这些字符时,请按这种写法,并用下面的方法验证。讲代理的页面本身没有谈密码里的特殊字符,这一条是按 URL 规则推出来的。命令里敲的密码会留在终端历史里;手册提醒,这里的安全注意事项和 --http-password 相同。

用选项传账号密码:示例

export https_proxy=http://HOST:PORT/
wget --proxy-user=USERNAME --proxy-password=PASSWORD https://example.com/file.zip

请把 HOST、PORT、USERNAME 和 PASSWORD 换成「我的资产」里的值。

写进 .wgetrc 启动文件

Wget 还会从它的启动文件 .wgetrc 读取设置。手册说,Wget 先读全局文件(默认 /usr/local/etc/wgetrc),再读你自己的文件:如果设置了 WGETRC 变量,就读它指向的文件,否则读 $HOME/.wgetrc;你自己的文件会覆盖全局文件。--config 选项可以指定另一个文件,--no-config 则不读任何配置文件。那里的代理命令会覆盖环境里的代理设置:http_proxy、https_proxy、no_proxy、proxy_user 和 proxy_password,另外还有 use_proxy,设成 off 就表示即使设了代理变量也不使用代理。手册没有说 Windows 上的 $HOME 在哪里;拿不准的话,就用上面的环境变量:它不需要任何文件。

.wgetrc 里的代理设置:示例

http_proxy = http://HOST:PORT/
https_proxy = http://HOST:PORT/
proxy_user = USERNAME
proxy_password = PASSWORD
no_proxy = .internal.example

请把 HOST、PORT、USERNAME 和 PASSWORD 换成「我的资产」里的值。

哪些地址不走代理

把内网或本机的地址放进 no_proxy,这是一串逗号分隔的域名后缀。手册里的例子是:no_proxy 设为 .mit.edu 时,访问 MIT 的文档就不用代理。只想这一次不用代理,加 --no-proxy(手册说即使设了环境变量,它也会让 Wget 不使用代理)。

单次不走代理:示例

wget --no-proxy http://internal-server.local/data.csv

网址只是示例;--no-proxy 只对这一次运行生效。

SOCKS5

手册的代理一页写的是 Wget 支持 HTTP 和 FTP 下载的代理,没有提到 SOCKS。所以本文只用 HTTP 代理地址:生成 Proxy302 代理时协议请选 HTTP。

怎么关掉代理

关掉终端窗口,或者运行 unset http_proxy https_proxy no_proxy。把 .wgetrc 里的代理行删掉,或在其中写 use_proxy = off。只想这一次不用,就加 --no-proxy。

怎么确认 Wget 在用代理

  1. 让一个服务告诉你地址

    下面的第一条命令把 https://ipinfo.io/json 的回答存进文件并打印出来。里面的地址应该是代理的出口,而不是你自己的。

  2. 和 curl 对比

    第二条命令用 curl 通过同一个代理发出请求。如果 curl 行而 Wget 不行,就找找有没有遗留的 .wgetrc 或 no_proxy 条目。

  3. 再下载个小文件

    设好代理后下载一个你能读到的小文件。

确认 Wget 在用代理:示例

wget -q -O ipinfo.json https://ipinfo.io/json && cat ipinfo.json
curl -x http://USERNAME:PASSWORD@HOST:PORT https://ipinfo.io/json

请把 HOST、PORT、USERNAME 和 PASSWORD 换成「我的资产」里的值。

常见错误

• 407 Proxy Authentication Required:代理拒绝了账号或密码,或者根本没收到。请写进 URL,或用 --proxy-user 和 --proxy-password 传入,并检查百分号编码。

• Connection refused(连接被拒绝):HOST 或 PORT 不对,或者租期已结束。用上面的 curl 命令测同一个地址。启动文件里的 retry_connrefused = on 会让 Wget 把被拒绝的连接当成临时错误并重试。

• Wget 直连了:检查 no_proxy、.wgetrc 里的 use_proxy = off,或别名里的 --no-proxy。

• https:// 的下载没走代理:确认设置了 https_proxy,而不只是 http_proxy。

用 Proxy302 怎么做

这里的每条命令都只需要 Proxy302 代理的主机、端口、账号和密码。Wget 用的是 HTTP 地址,所以生成代理时协议选 HTTP。动态住宅流量按 GB 计费,出口国家在生成代理时设置;HTTP 在 proxy.proxy302.com 的 2222 端口,SOCKS5 在 3333 端口。静态 ISP IP 在整个租期内固定、不轮换,适合希望每次都从同一个地址出去的工具。HTTP 还是 SOCKS5 在购买时选择,一个 IP 只带一种协议。

用 Proxy302 怎么做:步骤

  1. 第 1 步

    打开动态住宅页面,选择线路,「协议」保持 HTTP,然后点击「确认费用并生成」。

  2. 第 2 步

    打开「我的资产」(控制台里放着你买到的全部代理),复制 HOST(地址)、PORT(端口)、USERNAME(账号)和 PASSWORD(密码)。「连接工具」页里有填好你自己连接信息的现成示例。

  3. 第 3 步

    把这些值填进上面的命令。

  4. 第 4 步

    通过代理访问 https://ipinfo.io/json 确认出口。

  5. 第 5 步

    在中国大陆,先在「连接工具」页打开辅助工具,使用代理期间保持开着。

价格与限制

低价线路每 GB 收费 US$1.50,100 GB 套餐每 GB US$1.35,300 GB 每 GB US$1.20。静态 ISP IP 一天 US$0.50,30 天 US$7.99。不提供免费试用,最小购买单位为 1 GB,或一个 IP 一天。可用的出口位置每天都会变化。

常见问题

https:// 链接 Wget 读哪个变量?

https_proxy。手册说 http_proxy 和 https_proxy 分别放 HTTP 和 HTTPS 连接所用代理的 URL。

代理 URL 本身要写 https:// 吗?

Proxy302 的 HTTP 代理在两个变量里都写 http://HOST:PORT/。https_proxy 名字里的 https 只表示它用于哪类下载。

Wget 能用 SOCKS5 代理吗?

手册里关于代理的那一页没有提到 SOCKS。请使用 HTTP 代理地址。

关掉终端后设置还在吗?

环境变量不会保留;.wgetrc 里的行会保留。

参考资料

6
  1. GNU Wget Manual: Proxies

    官方文档 · 确认日期:

    Wget 1.25.0 manual, node Proxies: Wget supports proxies for HTTP and FTP retrievals; the standard way is the variables http_proxy, https_proxy (URLs of proxies for HTTP and HTTPS connections), ftp_proxy and no_proxy (comma-separated list of domain extensions proxy should not be used for; .mit.edu example); --no-proxy / "proxy = on/off" suppress the proxy even if variables are set; startup-file http_proxy, https_proxy, ftp_proxy and no_proxy override the environment; proxy authorization supports only the Basic scheme; username and password go in the proxy URL (http://hniksic:[email protected]:8001/) or in proxy-user and proxy-password / proxy_user and proxy_password. Checked on 2 November 2026 against the official release documentation (doc/wget.texi in wget-1.25.0.tar.gz from https://ftp.gnu.org/gnu/wget/, released 2024-11-10), because www.gnu.org could not be reached; the gnu.org manual page is the same text.

    The page does not mention SOCKS or percent-encoding of special characters.

  2. GNU Wget Manual: Wgetrc Commands

    官方文档 · 确认日期:

    Node Wgetrc Commands. Checked on 2 November 2026 against the official release documentation (doc/wget.texi in wget-1.25.0.tar.gz from https://ftp.gnu.org/gnu/wget/, released 2024-11-10), because www.gnu.org could not be reached; the gnu.org manual page is the same text. http_proxy and https_proxy "instead of the one specified in environment"; no_proxy is a comma-separated list of domains for which no proxy is loaded; proxy_user and proxy_password set proxy authentication; use_proxy = off means do not use a proxy even when proxy-related environment variables are set, same as --no-proxy; retry_connrefused = on considers "connection refused" a transient error; output_document = file is the same as -O file; quiet = on/off is the same as -q.

    The commands are described one by one; the file location is in the Wgetrc Location node (next source).

  3. GNU Wget Manual: HTTP Options

    官方文档 · 确认日期:

    Node HTTP Options. Checked on 2 November 2026 against the official release documentation (doc/wget.texi in wget-1.25.0.tar.gz from https://ftp.gnu.org/gnu/wget/, released 2024-11-10), because www.gnu.org could not be reached; the gnu.org manual page is the same text. --proxy-user=user and --proxy-password=password specify the username and password for authentication on a proxy server; Wget encodes them with the basic authentication scheme; security considerations similar to --http-password apply.

    It says nothing about SOCKS.

  4. GNU Wget Manual: Wgetrc Location

    官方文档 · 确认日期:

    Node Wgetrc Location. Checked on 2 November 2026 against the official release documentation (doc/wget.texi in wget-1.25.0.tar.gz from https://ftp.gnu.org/gnu/wget/, released 2024-11-10), because www.gnu.org could not be reached; the gnu.org manual page is the same text. Global file /usr/local/etc/wgetrc by default; then the file named by WGETRC if set, else $HOME/.wgetrc; the user file overrides the global one. The Overview node adds --config and --no-config.

    It does not describe Windows locations.

  5. GNU Wget Manual: URL Format

    官方文档 · 确认日期:

    Node URL Format. Checked on 2 November 2026 against the official release documentation (doc/wget.texi in wget-1.25.0.tar.gz from https://ftp.gnu.org/gnu/wget/, released 2024-11-10), because www.gnu.org could not be reached; the gnu.org manual page is the same text. Unsafe characters in a URL can be written as %xy; % is %25, : is %3A, @ is %40.

    It is about the URLs given to Wget, not specifically proxy URLs.

  6. Proxy302 产品事实与价格表

    产品观察 · 确认日期:

    Product facts file of the site (values checked against the console, the backend and the price table on 18-19 October 2026): products, prices in US$ (1 PTC = US$1), lease terms, protocols and ports, countries, quantity limits, no free trial.

准备好试试了吗?

注册账号、充值一次,就能选动态住宅、静态 ISP 或数据中心 IP,几分钟配进你的浏览器。