Vagrant Refused via browser

12,738

Make sure to forward the 80 port from the guest so you can access the vm from your browser. Edit your Vagrantfile and make sure to have a line like (by default when doing vagrant init I believe this is commented)

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

You can then access your web server (if running on the VM) from http://127.0.0.1:8080 or http://localhost:8080

If you prefer to use a fixed private IP, you will need to add

config.vm.network :private_network, ip: "192.168.33.10"

you will then access the vm server using http://192.168.33.10

note:

  • if you have nothing running on the port 80 nothing will be displayed (obviously). you can run sudo netstat -ant and check you have a process running on port 80

  • Adjust the port number from the example with the service you're running if it runs on another port.

Share:
12,738
Elevant
Author by

Elevant

Updated on June 17, 2022

Comments

  • Elevant
    Elevant almost 2 years

    I am very new to using Vagrant in my development workflow, however when setting up the box using vagrant up and then accessing it via my host i get a connection refused with my browser.

    Is all that needs to be done to work is: vagrant init scotch/box vagrant up

    ?

  • Elevant
    Elevant over 8 years
    i dont mean inside the actual box i mean like outside on my host. Does the same apply?
  • Frederic Henri
    Frederic Henri over 8 years
    yes it applies for your host, the goal is not to access the vm directly but accessing from your host
  • Elevant
    Elevant over 8 years
    Thanks i will give that a go just doing a postinstall atm
  • Elevant
    Elevant over 8 years
    I did uncomment the private network and used that ip in my browser.
  • Elevant
    Elevant over 8 years
    Is it possible to use a specific ip instead of localhost eg 192.168.33.10?
  • Frederic Henri
    Frederic Henri over 8 years
    @Elevant giving an example with fixed IP
  • Elevant
    Elevant over 8 years
    Thanks for the example of the fixed IP i have tried it with no avail. I vagrant init and then vagrant up and postinstall.sh is there specific setup i need to do in vm or my host? my host already had a past apache/mysql/php setup before vagrant is that interfering?
  • Frederic Henri
    Frederic Henri over 8 years
    can you check you can access your site from the vm (curl or something) ? do you have specific http.conf for apache ?
  • Elevant
    Elevant over 8 years
    no i did a restore of my http.conf but of note is that on the vm i cannot find apache or nginx just has node and stuff setup?
  • Frederic Henri
    Frederic Henri over 8 years
    run sudo netstat -ant and check you have something running on port 80, you should have something like 0 0.0.0.0:80
  • Elevant
    Elevant over 8 years
    I think it was just related to the specific box i have it working now. Thanks.