问题描述
wget 使用 https 协议的代理使用不上?有没有遇到过这种情况?
我有遇到过这种情况,如下配置了 https_proxy
的地址
export https_proxy=https://user:pass@some.example.com:443
wget https://www.baidu.com
不会得到正确的响应,如下
无法读取代理响应:连接被对方重设
连接已经重置。
问题的分析
并不是因为代理服务器的用户名或密码未设置,因为即便设置了 wget 参数 --proxy-user=
, 以及 --proxy-password=
也会是同样的错误。
这是由于代理服务是 https 协议的缘故。
问题的处理
处理办法是将 https 中的 s
拿掉,直接用 http 协议的代理,并重新指定 http 代理的端口。
防火墙阻断
出现新的问题。
但是如果直接用 http 协议的代理,那么仍然无法访问国外的 http 资源,这是因为众所周知的网络原因。
于是,为了能够让 http 协议的代理能够访问国外的 http 资源,就得另想办法。
我想到的办法是,在 http 协议外加一层 tunnel。利用的是 ssh 的端口转发,在本地网络上建立映射了到代理服务器的一个 http 的代理地址。加转发的端口后,用户名和代理密码仍然是需要的。
在 m.local.example.com 的本地机器上执行端口转发的命令
ssh -NL 0.0.0.0:7001:localhost:7001 -o "ServerAliveInterval 60" some.example.com
于是就可以使用 https_proxy
了,如下
export https_proxy=http://user:pass@m.local.example.com:7001
如上,去掉了 s
读完了
本文提出了一种解决 wget 使用 https 协议的网络代理出错问题的办法,适用于具备 macOS, linux 的环境,且具备代理服务器的 ssh 权限的情形。
全文完。
还没完,补充道
我用 wget2
sudo apt-get install wget2
wget2 的用法
添加代理地址和代理地址的登录信息,参数选项
- --http-proxy-user
- --http-proxy-password
环境变量
https_proxy=
(经测试)这个 https_proxy
环境变量带不带 user:pass
不是必需,效果都一样。
全文完。