Port fowarding for Nginx using Vagrant

Raphael

I'm facing an issue: I'm using Windows 7 and running a Vagrant Box (Lucid32), and inside it, a Nginx Server.

If i run

$ curl localhost:80 

I can see the Nginx's welcome page perfectly.

However, in Windows, the port 2000 (the fowarding I've made) can't reach a thing.

Otherwise, if I run the rails server, I can reach it, outside the VM.

I made this basic configuration for the 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;
  }

}

My vagrantfile:

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

Output by vagrant up command:

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

Thanks!

BrianC

If I'm reading everything correctly, I think you may have the port numbers reversed. For example if you have nginx running on port 8080 inside the guest OS (Linux) and want it to appear as port 80 on the host OS (Windows), that line would look like:

config.vm.network :forwarded_port, guest: 8080, host: 80

However, the Vagrantfile you posted and the log from vagrant up don't seem to match. (The same ports aren't mentioned in each case.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related