38
49

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Proxy環境下でのVagrant設定

Last updated at Posted at 2016-10-21

Proxy環境下でvagrant upを行うメモ

環境

Windows 10 Pro 64bit
Vagrant 1.8.5

1. vagrant-proxyconfプラグインをインストール

vagrant-proxyconf
ゲストOSへの環境変数設定(HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxy)
apt, yum, gitなどなどのプロキシ設定を行ってくれるプラグイン。

> set http_proxy=http://{proxy_ip}:{proxy_port}
> set https_proxy=http://{proxy_ip}:{proxy_port}

> vagrant plugin install vagrant-proxyconf

http_proxy, https_proxyはvagrantのプラグインインストールのGemで必要

2. Vagrantfileの編集と実行

Vagrantfile
Vagrant.configure(2) do |config|
    # ~省略~

    # プロキシ設定
    if Vagrant.has_plugin?("vagrant-proxyconf")
        config.proxy.http     = "http://{proxy_ip}:{proxy_port}"
        config.proxy.https    = "http://{proxy_ip}:{proxy_port}"
        config.proxy.no_proxy = "localhost,127.0.0.1"
    end
end
> vagrant up

(おまけ) プロキシ設定を環境変数から読む

Vagrantfile
Vagrant.configure(2) do |config|
    # ~省略~

    # プロキシ設定
    if Vagrant.has_plugin?("vagrant-proxyconf") && ENV['PROXY_URL']
        puts '- Proxy Setting ----------------------------------'
        puts ENV['PROXY_URL']
        config.proxy.http     = ENV['PROXY_URL']
        config.proxy.https    = ENV['PROXY_URL']
        config.proxy.no_proxy = "localhost,127.0.0.1"
        puts '--------------------------------------------------'
    end
end
> set PROXY_URL=http://{proxy_ip}:{proxy_port}
> vagrant up

PROXY_URLに設定する値はダブルクォート(")つけない。
つけるとaptとかの設定ファイル(/etc/apt/apt.conf.d/01proxy)でシンタックスエラーになってしまう。

38
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
49

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?