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

  • 相关阅读:
    [杂说]网络是基础生产工具
    这几天的工作
    [代码]大家来动动脑筋吧
    测试
    [基础] 如何使用extern和static限定符
    元宵节快乐
    复杂的“人"
    C# SMTP发邮件不支持465端口的解决方案,网易企业邮箱
    软件三层架构模型
    ASP.NET MVC 使用二级域名来注册Area区域
  • 原文地址:https://www.cnblogs.com/hupeng1234/p/9783336.html
Copyright © 2011-2022 走看看