Vagrant Refused via browser

2020-07-18 05:56发布

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

?

3条回答
你好瞎i
2楼-- · 2020-07-18 06:20

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.

查看更多
Juvenile、少年°
3楼-- · 2020-07-18 06:24

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

查看更多
虎瘦雄心在
4楼-- · 2020-07-18 06:28

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.

查看更多
登录 后发表回答