端口转发不适用于 Virtualbox 5.1.2 中的 Web 服务
Port Forwarding not working for web services in Virtualbox 5.1.2
我在基于 Centos 7 的 VM 中的端口 5000 上有一个节点应用程序 运行。当我在 VM 中打开浏览器时,我可以访问 http://localhost:5000。我也在 Virtualbox 中转发端口 5000/TCP。直到最近,我才能够在我的主机上访问相同的 URL。我可以通过 SSH 连接到机器,所以我可以假设来宾添加不是罪魁祸首。
当我从主机 curl 时,我得到以下输出:
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 成功:
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 的问题吗?
原来我已经下载了更新版本的 Vagrant Box,它现在启用了以前没有的防火墙。一个懒惰的解决方法是:
sudo systemctl stop firewalld
sudo systemctl disable firewalld
或者,仅允许端口 5000 上的出站流量
firewall-cmd --zone=public --add-port=5000/tcp --permanent
停止 VM 机器中的防火墙守护进程对我有用。谢谢@Harry King
sudo systemctl 停止 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
我在基于 Centos 7 的 VM 中的端口 5000 上有一个节点应用程序 运行。当我在 VM 中打开浏览器时,我可以访问 http://localhost:5000。我也在 Virtualbox 中转发端口 5000/TCP。直到最近,我才能够在我的主机上访问相同的 URL。我可以通过 SSH 连接到机器,所以我可以假设来宾添加不是罪魁祸首。
当我从主机 curl 时,我得到以下输出:
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 成功:
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 的问题吗?
原来我已经下载了更新版本的 Vagrant Box,它现在启用了以前没有的防火墙。一个懒惰的解决方法是:
sudo systemctl stop firewalld
sudo systemctl disable firewalld
或者,仅允许端口 5000 上的出站流量
firewall-cmd --zone=public --add-port=5000/tcp --permanent
停止 VM 机器中的防火墙守护进程对我有用。谢谢@Harry King
sudo systemctl 停止 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