zoukankan      html  css  js  c++  java
  • work behind corp proxy

    =================================
    proxy 的写法
    =================================
    一般写法是:
    http://my.proxy.address:8080

    带密码的验证写法如下,
    http://domain/username:password@servername:port/
    用户密码往往是 windows 域的账号密码, 密码最好不要带空格和%号和@号和冒号, 一旦包含了这些特殊字符就必须转义, 很麻烦, 所以最简单的方式是修改密码, 而不是转义.

    =================================
    chrome
    =================================
    chrome 的启动命令增加下面启动参数:
    # Disable proxy
    --no-proxy-server

    # Manual proxy address
    --proxy-server=<scheme>=<uri>[:<port>][;...] | <uri>[:<port>] | "direct://"

    # Manual PAC address
    --proxy-pac-url=<pac-file-url>

    # Disable proxy per host
    --proxy-bypass-list=(<trailing_domain>|<ip-address>)[:<port>][;...]

    =================================
    vs code 的配置
    =================================
    vs code 经常在线安装扩展, 下面的网络 proxy 设置方法
    方法 1: 在 preferences 中设定如下配置, 一般"http.proxyStrictSSL" 应该配置为false
    // Place your settings in this file to overwrite the default settings
    {
    "http.proxy": "http://my.proxy.address:8080",
    "https.proxy": "http://my.proxy.address:8080",
    "http.proxyStrictSSL": false
    }


    方法2: vs code 和基于 Electron 的所有应用都是基于 Chromium的, 它们都和 Chrome 有同样的启动命令参数, 可以使用 chrome 的启动命令行, 见 chrome 的配置说明.


    =================================
    eclipse 设置
    =================================
    在 eclipse.ini 配置如下参数, 即可启用Windows的系统代理,
    -Djava.net.useSystemProxies=true

    下面是一些其他设置项, 可以按需启用.
    // NoProxy
    -Dhttp.noProxyHosts=localhost|127.0.0.1|192.168.0.1

    // HTTP
    -Dhttp.proxyHost=http://proxy.memorynotfound.com
    -Dhttp.proxyPort=80

    // HTTPS
    -Dhttps.proxyHost=https://proxy.memorynotfound.com
    -Dhttps.proxyPort=443

    =================================
    npm 的配置
    =================================
    使用如下命令设置代理, 或者直接编辑 C:Users<username>.npmrc 文件

    npm config set proxy=http://<username>:<pass>@proxyhost:<port>
    npm config set https-proxy=http://<uname>:<pass>@proxyhost:<port>
    npm config set strict-ssl false
    npm config set registry "http://registry.npmjs.org/"

    最好使用国内镜像站点, 比如下面的前两个:
    cnpm --- http://r.cnpmjs.org/
    taobao - http://registry.npm.taobao.org/
    npm ---- https://registry.npmjs.org/
    eu ----- http://registry.npmjs.eu/
    au ----- http://registry.npmjs.org.au/
    sl ----- http://npm.strongloop.com/
    nj ----- https://registry.nodejitsu.com/


    =================================
    Maven configuration
    =================================
    Edit the proxies session in your ~/.m2/settings.xml file, 内容如下:
    <proxies>
    <proxy>
    <id>id</id>
    <active>true</active>
    <protocol>http</protocol>
    <username>username</username>
    <password>password</password>
    <host>host</host>
    <port>port</port>
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    </proxies>

    =================================
    Gradle configuration
    =================================
    If you want to set these properties globally then add it in USER_HOME/.gradle/gradle.properties file

    ## Proxy setup
    systemProp.proxySet="true"
    systemProp.http.keepAlive="true"
    systemProp.http.proxyHost=host
    systemProp.http.proxyPort=port
    systemProp.http.proxyUser=username
    systemProp.http.proxyPassword=password
    systemProp.http.nonProxyHosts=local.net|some.host.com

    systemProp.https.keepAlive="true"
    systemProp.https.proxyHost=host
    systemProp.https.proxyPort=port
    systemProp.https.proxyUser=username
    systemProp.https.proxyPassword=password
    systemProp.https.nonProxyHosts=local.net|some.host.com
    ## end of proxy setup


    =================================
    Git configuration
    =================================
    Use these commands:

    git config --global http.proxy http://username:password@host:port
    git config --global https.proxy http://username:password@host:port
    git config --global http.sslVerify false

    Or you can edit directly your ~/.gitconfig file:

    [http]
    proxy = http://username:password@host:port
    [https]
    proxy = http://username:password@host:port


    =================================
    使用cntlm管理代理
    =================================
    上面的软件有对应的设置接口, 对于另一些软件根本没有这样的接口, 所以不能上面的类似做法. 即使上述方法可用, 一旦修改Windows密码, 还需要重新设置一遍. 这里介绍一个终极的做法, 使用 cntlm 软件.
    软件下载 http://cntlm.sourceforge.net/

    (1) 安装的时候, 最好选择默认安装路径, 否则后续运行会有问题.
    (2) 修改安装目录的 cntlm.ini, 可以在 ini 文件中指定明文密码, 如果不想设置明文密码, 可以使用下面命令行, 生成hash后的密码.
    cntlm -H
    cntlm.ini 文件Listen 设置项默认是 3128 , 也就是将来的代理接口是, http://127.0.0.1:3128 , 如果将来的代理要开放给其他机器, 最好设置成 your_ip:3128 格式, 或者 0.0.0.0:3128 即可.  
    (3) 验证设置是否正确, 通过访问百度来验证
    cntlm -c /path/to/cntlm.ini -M http://www.baidu.com
    运行后会要求输入登录代理的密码,输入后,如果配置正确,会返回200响应和PassNTLMv2
    (4) 启动 cntlm 服务
    使用命令启动服务, C:WindowsSystem32 et.exe start /path/to/cntlm.exe
    或者使用 cntlm 的开始菜单start service 来启动.

    (5)cntlm 程序报错最有可能的原因是, cntlm.exe 找不到 cntlm.ini 文件, 一般修改注册表会解决这个问题的.
    Open regedit.exe and go to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicescntlmParameters.
    Then change the AppArgs key to
    -f -c "C:Program FilesCntlmcntlm.ini"


    =================================
    boot2docker 的设置
    =================================
    1. 域名服务器的修改,  先在 HostOS windows 的 CMD 窗口执行 nslookup, 能得到域名服务器的ip. 将域名服务器加到 /etc/resolv.conf 文件中, 增加如下一行内容:
    nameserver dns_server_ip

    需要说明的是 /etc/resolv.conf 在每次重启 boot2docker 后都会被重置, 最好是将它保存到 /var/lib/boot2docker/profile 文件中.

    2. 在 /var/lib/boot2docker/profile 设置 registry 和 dns 信息.
    需要说明的是:
    1. registry-mirror 和普通 docker registry 区别在于, mirror 只能 pull 不能 push.
    2. 默认情况下, docker 对于 http 类型的私服是不信任的, 如果一定要使用, 需要将该私服加到 insecure-registry 参数中.
    3. insecure-registry 和 dns 参数可以设置多个.
    4. https://docker.mirrors.ustc.edu.cn 是国内比较好用的一个mirror, 不要注册就可以使用.

    内容如下: 

    EXTRA_ARGS="
    --dns dns_server_ip
    --insecure-registry registry_server:5000
    --registry-mirror https://docker.mirrors.ustc.edu.cn
    "

    3. 在 /var/lib/boot2docker/profile 文件中,   export proxy相关的设置.
    说明: 192.168.1.100 是 boot2docker VM 的IP, 将它加到 NO_PROXY 中, 将 localhost, 127.0.0., 10., /var/run/docker.sock 也加到 NO_PROXY 中, 内容如下:

    export HTTP_PROXY=http://my.proxy.address:8080
    export HTTPS_PROXY=http://my.proxy.address:8080
    export NO_PROXY=192.168.1.100,localhost,/var/run/docker.sock,127.0.0.*,10.*,192.168.*
    export http_proxy=http://my.proxy.address:8080
    export https_proxy=http://my.proxy.address:8080
    export no_proxy=192.168.1.100,localhost,/var/run/docker.sock,127.0.0.*,10.*,192.168.*

    或者在创建 boot2docker 虚拟机时就指定代理设置, 命令行如下:
    docker-machine create -d virtualbox
    --engine-env HTTP_PROXY=http://my.proxy.address:8080
    --engine-env HTTPS_PROXY=http://my.proxy.address:8080
    --engine-env NO_PROXY=192.168.1.100,localhost,/var/run/docker.sock,127.0.0.*,10.*,192.168.*
    default


    4. [可选]在 HostOS windows 设置几个环境变量:
    它们是 HTTP_PROXY 和 HTTPS_PROXY 和 NO_PROXY, 取值同上.

    5. docker 命令
    (1)docker pull 等命令会自动使用上面的代理设置, 示例如下:
    docker pull hello-world:latest

    (2)docker build 并不会自动读取上面的代理设置, 需要在docker build 命令中指定代理.
    docker build --build-arg http_proxy=http://169.254.123.45:3128
    --build-arg https_proxy=http://169.254.123.45:3128
    -t myawesomeimage:latest .

    (3)docker 容器进程使用代理
    假设一个 Java 程序, 下面的 test.sh 是容器的entry point脚本.

    if [[ ! -z "$http_proxy" ]] || [[ ! -z "$https_proxy" ]]; then
    export JAVA_OPTS="-Djava.net.useSystemProxies=true $JAVA_OPTS -Dhttp.noProxyHosts=${POSTGRES_IP}"
    fi

    容器启动时候, 可以传入 proxy 设置.
    sudo docker run -e "http_proxy=http://myproxy.example.com:8080"
    -e "https_proxy=https://myproxy.example.com:8080"
    -e "POSTGRES_IP=192.168.100.101"
    -d Cronubuntu test.sh

    =================================
    python pip 代理
    =================================
    pip 在联网时会读取环境变量 http_proxy 和 https_proxy
    export http_proxy=http://username:password@proxyURL:portNumber
    export https_proxy=http://username:password@proxyURL:portNumber

    或者直接在 install 时, 指定proxy地址
    pip --proxy=http://username:password@proxyURL:portNumber install flask


    =================================
    CentOS 的yum 代理
    =================================
    在 /etc/yum.conf 文件中, 增加下面一行内容.

    proxy=http://username:password@proxyURL:portNumber


    =================================
    参考
    =================================
    https://www.jhipster.tech/configuring-a-corporate-proxy/
    https://crondev.com/running-docker-behind-proxy/
    https://segmentfault.com/a/1190000004827169
    https://mandie.net/2017/12/10/docker-for-windows-behind-a-corporate-web-proxy-tips-and-tricks/
    https://exceptionshub.com/using-npm-behind-corporate-proxy-pac.html
    http://blog.majcica.com/2016/01/13/tough-life-behind-a-proxy/
    https://memorynotfound.com/configure-http-proxy-settings-java/

  • 相关阅读:
    HTML5结构
    HTML5新增的非主体元素header元素、footer元素、hgroup元素、adress元素
    CF GYM 100703G Game of numbers
    CF GYM 100703I Endeavor for perfection
    CF GYM 100703K Word order
    CF GYM 100703L Many questions
    CF GYM 100703M It's complicate
    HDU 5313 Bipartite Graph
    CF 560e Gerald and Giant Chess
    POJ 2479 Maximum sum
  • 原文地址:https://www.cnblogs.com/harrychinese/p/hehide-proxy.html
Copyright © 2011-2022 走看看