【问题标题】:Port Forwarding not working for web services in Virtualbox 5.1.2端口转发不适用于 Virtualbox 5.1.2 中的 Web 服务
【发布时间】:2016-12-17 05:15:19
【问题描述】:

我有一个节点应用程序在端口 5000 上基于 Centos 7 的 VM 中运行。当我在 VM 中打开浏览器时,我可以访问 http://localhost:5000。我也在 Virtualbox 中转发端口 5000/TCP。直到最近,我才能够访问主机上的相同 URL。我能够通过 SSH 连接到机器,所以我可以假设客人添加不是罪魁祸首。

当我从主机卷曲时,我得到以下输出:

curl -v http://localhost:5000
* Rebuilt URL to: http://localhost:5000/
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.46.0
> Accept: */*
>
* Recv failure: Connection was reset
* Closing connection 0
curl: (56) Recv failure: Connection was reset

来自客人的卷曲成功:

curl -v localhost:5000
* About to connect() to localhost port 5000 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: no-cache="Set-Cookie, Set-Cookie2"
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-XSS-Protection: 1; mode=block
< Content-Type: text/html; charset=utf-8
< Content-Length: 13545
< ETag: W/"34e9-XRkZVDhS9RNYciepFhTD7A"
< Vary: Accept-Encoding
< Date: Wed, 10 Aug 2016 17:11:16 GMT
< Connection: keep-alive
< 
<!DOCTYPE html>...

端口转发设置如下所示 - 只有 SSH 有效,尽管我已尝试向我要访问的服务添加和删除主机 IP。

如何进一步解决此问题?

这可能是最新版本的 virtualbox 的问题吗?

【问题讨论】:

  • 您的 VirtualBox 端口转发设置是什么样的?当您发出 curl 请求时,这是在 VM 上还是在您的主机上?对面(VM/主机)是什么样的?
  • 感谢 Lucas,我​​已经更新了问题,以便在访客和主机上都显示 curl。

标签: node.js virtualbox centos7


【解决方案1】:

停止 VM 机器中的防火墙守护程序对我有用。谢谢@Harry King

sudo systemctl stop firewalld

禁用前的卷曲结果:

* Recv failure: Connection was reset
* Closing connection 0
curl: (56) Recv failure: Connection was reset

禁用后:

< HTTP/1.1 404
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Fri, 30 Oct 2020 06:47:43 GMT
<
{"timestamp":1604040463217,"status":404,"error":"Not Found","message":"No message available","path":"/"}* Connection #0 to host 127.0.0.1 left intact

【讨论】:

    【解决方案2】:

    原来我已经下载了一个更新版本的 Vagrant Box,它现在启用了以前没有的防火墙。一个懒惰的解决方法是:

    sudo systemctl stop firewalld
    sudo systemctl disable firewalld
    

    或者,只允许端口 5000 上的流量出站

    firewall-cmd --zone=public --add-port=5000/tcp --permanent
    

    【讨论】:

      猜你喜欢
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 2014-10-03
      • 2017-11-02
      • 2014-05-25
      • 2020-10-23
      相关资源
      最近更新 更多