wanlifeipeng

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

代理

格式

# 设置http代理
export http_proxy=

# 设置https代理
export HTTPS_PROXY=

# 设置ftp代理
export FTP_PROXY=

# 同时设置http、https以及ftp代理
export ALL_PROXY=

在终端临时生效

# 设置代理,只在当前终端有效
$ export http_proxy=http://<IP>:<PORT>
或是
$ export http_proxy=socks5://127.0.0.1:1080
$ export HTTPS_PROXY=socks5://127.0.0.1:1080

# 取消代理
$ unset http_proxy
$ unset https_proxy

写入配置文件(如: .bashrc)永久有效

$ vi ~/.bashrc

# 添加如下内容:
# set proxy
function setproxy() {
    export http_proxy=socks5://127.0.0.1:1080
    export HTTPS_PROXY=socks5://127.0.0.1:1080
    export FTP_PROXY=socks5://127.0.0.1:1080
}

# unset proxy
function unsetproxy() {
    unset http_proxy HTTPS_PROXY FTP_PROXY
}

保存退出,执行source ~/.bashrc使得配置立即生效。或是关闭当前终端,重新打开,在终端中输入:

# 设置代理
$ setproxy

# 取消代理
$ unsetproxy

socks5和socks5h的区别

In a proxy string, socks5h:// and socks4a:// mean that the hostname is resolved by the SOCKS server. socks5:// and socks4:// mean that the hostname is resolved locally

socks5(本地解析hostname)

$export HTTPS_PROXY=socks5://127.0.0.1:1080
$curl https://www.google.com
curl: (51) SSL: certificate subject name (www.beforeprom.com) does not match target host name 'www.google.com'

socks5h(由socks server解析hostname)

$ export HTTPS_PROXY=socks5h://127.0.0.1:1080
$ curl https://www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description">
....

也就是说socks5适合本地能够解析目标主机域名(比如github.com)但是访问速度慢,来提高下载速度
socks5h用与本地不能解析目标主机域名(比如google),由代理服务器解析目标主机域名

curl通过-x设置代理

curl -x socks5h://127.0.0.1:1080 www.google.com

curl、wget与pac的关系

pac是js文件,curl和wget不能解析js文件。
也就是说,默认情况下,系统代理模式设为pac模式
此时浏览器已经可以访问被墙的网站,但是wget和curl却不行,必须通过http_proxyHTTPS_PROXY指定代理,才能访问

posted on 2017-10-13 22:35  wanlifeipeng  阅读(18776)  评论(0编辑  收藏  举报