Vagrant Refused via browser
Asked Answered
P

4

6

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

?

Postexilian answered 17/9, 2015 at 12:45 Comment(2)
What OS are you running inside the Vagrant box? If Linux, and it's a Red Hat or CentOS distro, then you probably need to configure iptables to allow incoming web connections.Wivern
OK, that's Linux, Ubuntu distro, so iptables is likely not an issue. What port are you hitting with your browser? Since that box is running node.js, it may be that the web server is listening on port 3000, not 80 or 8080, and you'll need to configure your port forwarding accordingly or hit 192.168.33.10:3000.Wivern
E
7

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.

Eyot answered 17/9, 2015 at 12:53 Comment(10)
i dont mean inside the actual box i mean like outside on my host. Does the same apply?Postexilian
yes it applies for your host, the goal is not to access the vm directly but accessing from your hostEyot
Thanks i will give that a go just doing a postinstall atmPostexilian
Is it possible to use a specific ip instead of localhost eg 192.168.33.10?Postexilian
@Elevant giving an example with fixed IPEyot
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?Postexilian
can you check you can access your site from the vm (curl or something) ? do you have specific http.conf for apache ?Eyot
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?Postexilian
run sudo netstat -ant and check you have something running on port 80, you should have something like 0 0.0.0.0:80Eyot
I think it was just related to the specific box i have it working now. Thanks.Postexilian
P
0

By default, you get a NAT interface that you cannot connect into. You should define a private network in vagrant to make incoming connections available. Then, also check your VM's firewall settings.

Pawn answered 17/9, 2015 at 13:15 Comment(1)
I did uncomment the private network and used that ip in my browser.Postexilian
M
0

I had a similar problem and just wanted to share my solution, maybe it helps someone else. I couldnt reach the localhost:8080 via browser. The connection got interrupted everytime. After a long wasted time and search, I found my problem, it was due to the nginx.conf file.

#nginx config file
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    listen localhost;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location \ {
        try_files $uri $uri/ = 404;
    }
}

i forgot the backslash after location.... after adding it, i could restart my nginx via vagrant ssh and now it's working again

best totem

Melanism answered 26/10, 2018 at 8:40 Comment(0)
O
0

There are some provider-related issues when it comes to networking, especially with Hyper-V, that the get-started docs don't mention. See https://developer.hashicorp.com/vagrant/docs/providers/hyperv/limitations

Onomatology answered 18/12, 2022 at 2:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.