zoukankan      html  css  js  c++  java
  • 常用http/https以及socks5代理总结

    代理

    格式

    # 设置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指定代理,才能访问

  • 相关阅读:
    mysql 5.6
    mysql5.7 二进制包安装
    centos 6 编译安装httpd-2.4
    mysql 5.5源码包安装
    BZOJ4945 & 洛谷3825 & UOJ317:[NOI2017]游戏——题解
    BZOJ4943 & 洛谷3823 & UOJ315:[NOI2017]蚯蚓排队——题解
    BZOJ3435 & 洛谷3920 & UOJ55:[WC2014]紫荆花之恋
    BZOJ5343 & 洛谷4602 & LOJ2555:[CTSC2018]混合果汁——题解
    真·APIO2018滚粗记
    BZOJ4518:[SDOI2016]征途——题解
  • 原文地址:https://www.cnblogs.com/hupeng1234/p/9783336.html
Copyright © 2011-2022 走看看