Vagrant Port Forwarding on Mac OS X Lion

I am trying to connect to Centos 6.4 vm using Vagrant. I use salt as an initialization agent, and I have successfully installed apache, php, mysql packages. When I ssh in the apache field it works fine. I added the index.html file to / var / www and I get the contents back when I hang localhost: 80

Vagrant.configure("2") do |config| ## Chose your base box config.vm.box = "centos63" config.vm.box_url = "" ## For masterless, mount your salt file root config.vm.synced_folder "salt/roots/", "/srv/" ## Use all the defaults: config.vm.provision :salt do |salt| salt.verbose = true salt.run_highstate = true salt.minion_config = "salt/minion" end end Vagrant::Config.run do |config| config.vm.forward_port 80, 8080 config.vm.share_folder "mypath", "/var/www/leo", "." end 

I ran sudo lsof -i: 8080 on my local machine and did not give me any results. I also cleared the iptable config on the guest machine using iptables -F. When I twist the guest car

  curl -v 'localhost:8080' * About to connect() to localhost port 8080 (#0) * Trying ::1... * Connection refused * Trying 127.0.0.1... * Connection refused * Trying fe80::1... * Connection refused * couldn't connect to host * Closing connection #0 curl: (7) couldn't connect to host 

Do I need extras for guests? I looked around how to install this, but I'm not sure if it should be installed on the host or guest. Not sure what else to try.

+4
source share
2 answers

What you are trying to do here is not possible simply by using a stroller without using strollers as root . You can run Vagrant as root , I believe, but VirtualBox disagrees. You can continue to use the port number, or if you want or use port 80, there is a way.

I had this problem when my client asked me to install Wordpress Multisite. With Wordpress MS, you cannot have port numbers in the b / c url, some part of the url will not work correctly. I was surprised when I found out about this and did not want to return to using a program such as MAMP.

In any case, here are two ways to achieve this goal (none of them are very difficult). I am a Mac user, so these are answers on Mac, I will see if there is a version of Windows and update your answer when I can check it to make sure (see below, there is a way).

Method # 1 (Mac IP Firewall Utility):

In your stray file

 config.vm.forward_port 80, 8080 config.vm.forward_port 443, 8443 

This is pretty normal.

Now open a terminal and you can use the ipfw utility

 sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80 sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443 

Now that cmd is not permanent, you will have to restart cmd if you restart your computer. You can make this permanent, even though I include the link below that will explain the rest of # 1.

Web development on ports 80 and 443 in Vagrant

Path number 2 (Mac POW and Anvil):

If you don’t have Pow yet, get it! This is a really cool app. Install Pow and Anvil, you can find Anvil , and you can find Pow .

You can read the documents on how to configure them, but do not pay attention to the part of the "static" and "rack" sites, you need this part.

You will use Port Proxying through Pow to receive incoming traffic from mycoolsite.dev and redirect it to a virtual machine such as mycoolsite.dev:8080, and then the virtual machine will forward 8080 to 80 and back up your content will come.

After you install Anvil / Pow and run them, run this line:

 echo 8080 > ~/.pow/mycoolsite 

Then click Anvil on the taskbar (you may have to update it or close it and reopen it) and turn on the site, is that all? Indeed? Pow and Anvil rock !!

So there are two ways that I found, I'm sure there are some things you can do with your hosts file, and I used this bundle. However, these other methods that are available really make it easy to forget that the pesky hosts file.

Note for Windows users (and Mac users who don’t like the first 2 ways): you can use Vagrant Host Manager, you can learn how to configure it here on github . This is a firewall plugin and will basically edit your hosts for you, all you do is your firewall configuration and you should go after that. I just tested it on Windows 7 and it worked there, so it should be fine if you have any problems, just view the github docs or file to view the Vagrant Host Manager command.

+3
source

I changed the guest port to 5656 and it worked. When running lsof -i: 8080, I did not see any results, so I realized that nothing was using this port, maybe I was wrong.

0
source

Source: https://habr.com/ru/post/1487273/


All Articles