How to use vagrant in a proxy environment?

前端 未结 12 904
太阳男子
太阳男子 2020-12-07 08:10

My company\'s network is using proxy. So when I use vagrant up, it showed me a 401 permission error.

How can I do some setting to use vagrant?

相关标签:
12条回答
  • 2020-12-07 08:26

    Installing proxyconf will solve this, but behind a proxy you can't install a plugin simply using the command vagrant plugin install, Bundler will raise an error.

    set your proxy in your environment if you're using a unix like system

    export http_proxy=http://user:password@host:port
    

    or get a more detailed answer here: How to use bundler behind a proxy?

    after this set up proxyconf

    0 讨论(0)
  • 2020-12-07 08:28

    On windows, you must set a variable to specify proxy settings, download the vagrant-proxyconf plugin: (replace {PROXY_SCHEME}(http:// or https://), {PROXY_IP} and {PROXY_PORT} by the right values)

    set http_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
    set https_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
    

    After that, you can add the plugin to hardcode your proxy settings in the vagrant file

    vagrant plugin install vagrant-proxyconf --plugin-source http://rubygems.org
    

    and then you can provide config.proxy.xxx settings in your Vagrantfile to be independent against environment settings variables

    0 讨论(0)
  • 2020-12-07 08:30

    On a Windows host

    open a CMD prompt;

    set HTTP_PROXY=http://proxy.yourcorp.com:80
    set HTTPS_PROXY=https://proxy.yourcorp.com:443
    

    Substitute the address and port in the above snippets to whatever is appropriate for your situation. The above will remain set until you close the CMD prompt. If it works for you, consider adding them permanently to your environment variables so that you won't have to set them every time you open a new CMD prompt.

    0 讨论(0)
  • 2020-12-07 08:34

    Some Special characters in the password create problem in proxy. Either escape them or avoid having special characters in password.

    0 讨论(0)
  • 2020-12-07 08:36

    If your proxy requires authentication it is better to set the environment variable rather than storing your password in the Vagrantfile. Also your Vagrantfile can be used by others easily who are not behind a proxy.

    For Mac/Linux (in Bash)

    export http_proxy="http://user:password@host:port"
    export https_proxy="http://user:password@host:port"
    vagrant plugin install vagrant-proxyconf
    

    then

    export VAGRANT_HTTP_PROXY=${http_proxy}
    export VAGRANT_HTTPS_PROXY=${https_proxy}
    export VAGRANT_NO_PROXY="127.0.0.1"
    vagrant up
    

    For Windows use set instead of export.

    set http_proxy=http://user:password@host:port
    set https_proxy=https://user:password@host:port
    vagrant plugin install vagrant-proxyconf
    

    then

    set VAGRANT_HTTP_PROXY=%http_proxy%
    set VAGRANT_HTTPS_PROXY=%https_proxy%
    set VAGRANT_NO_PROXY="127.0.0.1"
    vagrant up
    
    0 讨论(0)
  • 2020-12-07 08:38

    You will want to install the plugin proxyconf since this makes configuring the proxy for the guest machines pretty straight forward in the VagrantFile

    config.proxy.http     = "http://proxy:8888"
    config.proxy.https    = "http://proxy:8883"
    config.proxy.no_proxy = "localhost,127.0.0.1"
    

    However, there's quite a few things that could still go wrong. Firstly, you probably can't install vagrant plugins when behind the proxy. If that's the case you should download the source e.g. from rubygems.org and install from source

    $ vagrant plugin install vagrant-proxyconf --plugin-source file://fully/qualified/path/vagrant-proxyconf-1.x.0.gem
    

    If you solve that problem you might have the fortune of being behind an NTLM proxy, which means that if you are using *nix on your guest machines then you still have some way to go, because NTLM authentication is not supported natively There are many ways of solving that. I've used CNTLM to solve tht part of the puzzle. It acts as glue between standard authorization protocols and NTLM

    For a complete walk through, have a look at this blog entry about setting vagrant up behind a corporate proxy

    0 讨论(0)
提交回复
热议问题