Vagrant 的端口转发不起作用 [英] Vagrant's port forwarding not working

查看:27
本文介绍了Vagrant 的端口转发不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 入门指南的末尾遇到了一个小问题代码>流浪者.我正在开发一个运行 Apache2 的 CentOS basebox(通过 Puppet 配置).我已经使用 Vagrantfile 中的以下行为 Web 请求设置了端口转发:

I'm running into a small problem at the end of the Getting Started guide for vagrant. I'm working on a CentOS basebox that has Apache2 running (provisioning via Puppet). I've set up port forwarding for web requests using the following line in Vagrantfile:

 config.vm.forward_port "web", 80, 4567

但是当我向该端口发出请求时,它们失败了.Safari 报的错误是 'Safari can't open the page http://localhost:4567/" 因为服务器意外断开连接.'

But when I make requests to that port, they fail. The error reported by Safari is 'Safari can’t open the page "http://localhost:4567/" because the server unexpectedly dropped the connection.'

我做了一个 vagrant reload 并在滚动中看到[default] -- web: 80 => 4567 (adapter 1)",那么我应该从哪里开始解决这个问题?谢谢.

I did a vagrant reload and saw "[default] -- web: 80 => 4567 (adapter 1)" in the scroll, so where should I begin to troubleshoot this? Thanks.

推荐答案

我会将其作为实际答案而不是更多评论.

I'll make this an actual answer instead of just more comments.

第一件事:在 VM 中尝试 curl 'http://localhost:80'.如果这不起作用,那么肯定不是端口转发.

First thing: try curl 'http://localhost:80' from within the VM. If that doesn't work, then it's definitely not the port forwarding.

下一步:在主机上尝试 curl -v 'http://localhost:4567/'.Curl 可能会为您提供比 Safari 更好的错误消息.

Next: try curl -v 'http://localhost:4567/' from your host machine. Curl might give you a better error message than Safari.

我会检查是否没有防火墙设置限制对端口 80 的访问.默认的 Vagrant VM (Ubuntu) 没有设置防火墙,但是您说您正在使用其他东西,所以它可能值得一试.

I'd check that there are no firewalls set up restricting access to port 80. The default Vagrant VM (Ubuntu) doesn't come with a firewall set up, but you said you're using something else, so it might be worth it to check.

如果不是这样,请尝试在端口 80 上列出除 Apache 之外的其他内容.Python 附带一个您可以使用的简单 HTTP 服务器——转到带有 index.html 的文件夹并运行 sudo python -m SimpleHTTPServer 80,然后尝试在两个框中使用 curl 进行匹配.如果可行,则可能是 Apache 配置问题.如果是这种情况,我没有足够的 Apache 经验来提供帮助(我使用 nginx).

If that's not it, try making something other than Apache listed on port 80. Python ships with a simple HTTP server you can use -- go to the folder with index.html and run sudo python -m SimpleHTTPServer 80, then try hitting that with curl from both boxes. If that works, then it's probably an Apache configuration issue. I don't have enough experience with Apache to help if that's the case (I use nginx).

这篇关于Vagrant 的端口转发不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆