问题描述
我对在开发工作流程中使用 Vagrant 非常陌生,但是当使用 vagrant up 设置框然后通过我的主机访问它时,我的浏览器拒绝了连接.
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.
工作所需要做的就是:vagrant init 苏格兰威士忌/盒子流浪起来
Is all that needs to be done to work is:vagrant init scotch/boxvagrant up
?
推荐答案
确保从来宾转发 80 端口,以便您可以从浏览器访问虚拟机.编辑您的 Vagrantfile
并确保有一行(默认情况下,在执行 vagrant init
我相信这是注释)
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
然后您可以从 http://127.0.0.1:8080 访问您的网络服务器(如果在 VM 上运行)a> 或 http://localhost:8080
You can then access your web server (if running on the VM) from http://127.0.0.1:8080 or http://localhost:8080
如果您更喜欢使用固定的私有 IP,则需要添加
If you prefer to use a fixed private IP, you will need to add
config.vm.network :private_network, ip: "192.168.33.10"
然后您将使用 http://192.168.33.10
注意:
如果您没有在端口 80 上运行任何内容,则不会显示任何内容(显然).您可以运行
sudo netstat -ant
并检查您是否在端口 80 上运行了一个进程
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.
这篇关于Vagrant 通过浏览器拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!