【发布时间】:2014-09-30 08:43:17
【问题描述】:
我遇到了一个问题: 我正在使用 Windows 7 并运行 Vagrant Box (Lucid32),并在其中运行 Nginx 服务器。
如果我跑了
$ curl localhost:80
我可以完美地看到 Nginx 的欢迎页面。
但是,在 Windows 中,端口 2000(我所做的转发)无法访问任何东西。
否则,如果我运行 rails 服务器,我可以在 VM 之外访问它。
我为 nginx.conf 做了这个基本配置:
server{
listen 8080;
server_name localhost;
access_log /usr/local/nginx/logs/access.log;
access_log /usr/local/nginx/logs/error.log;
location /{
root /var/www;
index index.html index.html;
}
}
我的流浪文件:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "lucid32"
config.vm.network :forwarded_port, guest: 3000, host: 3000 # rails
#config.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql
config.vm.network :forwarded_port, guest: 2000, host: 80 # apache/nginx
end
vagrant up 命令的输出:
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 2000 => 80. Now on port 2200.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] -- 3000 => 3000 (adapter 1)
[default] -- 2000 => 8080 (adapter 1)
[default] -- 2000 => 2200 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
cause things such as shared folders to not work properly. If you see
shared folder errors, please update the guest additions within the
virtual machine and reload your VM.
Guest Additions Version: 4.2.0
VirtualBox Version: 4.3
[default] Mounting shared folders...
[default] -- /vagrant
谢谢!
【问题讨论】: