问题:只有通过 Putty 或 cmd 打开 SSH 隧道后,我才能通过端口 8080 访问我的客户虚拟机ssh -L 8080:localhost:8080 [email protected]
我想要实现的目标是:当我启动我的 vagrant vm 时,我希望这个端口能够自动转发。
我正在尝试:
- 我已添加
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
到 Vagrantfile,它将右侧的第一个条目添加到网络设置。这似乎没什么区别,因为我仍然需要通过活动的 ssh 连接转发端口。我可以通过 putty 连接到您在图片中看到的转发的 ssh 端口localhost:2222
(该端口由 vagrant 镜像的维护者转发) - 我可以从 guest-vm 卷曲页面
curl -v 'http://localhost:8080'
并返回HTTP/1.1 200 OK
- 当我通过以下方式从主机卷曲页面时,我得到了什么
curl -v 'http://localhost:8080'
* Rebuilt URL to: http://localhost:8080/
* timeout on name lookup is not supported
* Trying ::1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.1
> Accept: */*
>
* Recv failure: Connection was aborted
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
* Closing connection 0
curl: (56) Recv failure: Connection was aborted
- 当我使用活动的 ssh 隧道从主机进行 curl 时:
$ curl -v 'http://localhost:8080'
* Rebuilt URL to: http://localhost:8080/
* timeout on name lookup is not supported
* Trying ::1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Content-Length: 974
< ETag: W/"3ce-MASXCzkp0dBO+UKSABDYEzPzueg"
< Date: Mon, 15 Apr 2019 13:21:35 GMT
< Connection: keep-alive
<
{ [974 bytes data]
100 974 100 974 0 0 60875 0 --:--:-- --:--:-- --:--:-- 951k<!DOCTYPE html>
<html>
<head>
....
如果您需要更多信息,请告诉我,因为我真的不太了解这个主题。