配置Vagrant代理时出现NameError: undefined local variable or method 'config'错误
NameError: undefined local variable or method 'config' in Vagrant Proxy Setup Hey there! Let's sort out this error you're hitting with your Vagrant proxy config. The issue here is pretty straightforward: when you added those three proxy lines to your global Vagrantfile, you didn't wrap them inside Vagrant's required configuration block. Without that block, Ruby (the language Vagrant uses under the hood) doesn't recognize the config variable you're trying to use.
Here's the correct way to structure your global Vagrantfile
The global Vagrantfile at C:\Users\<your username>\.vagrant.d\Vagrantfile needs to be wrapped in a Vagrant.configure block. Just replace your current three lines with something like this (swap in your actual proxy details):
Vagrant.configure("2") do |config| # Proxy configuration using proxyconf plugin config.proxy.http = "http://your-proxy-address:port" config.proxy.https = "http://your-proxy-address:port" config.proxy.no_proxy = "localhost,127.0.0.1" end
What's happening here?
- The
Vagrant.configure("2") do |config|line initializes Vagrant's configuration system and passes aconfigobject into the block. - Inside the block, you can safely use the
configvariable to set your proxy settings (and any other global Vagrant configs you want later). - The
endcloses the configuration block, telling Ruby where your Vagrant settings end.
Next steps to test
- Save the updated
Vagrantfile - Open your command prompt and run either
vagrant up(if you're starting a new machine) orvagrant reload(if you already have a machine running)
This should resolve the NameError and apply your proxy settings correctly across all your Vagrant projects.
内容的提问来源于stack exchange,提问作者Adam Burley

