SSH隧道无法正常工作 - 空服务器响应

时间:2015-07-02 19:03:09

标签: ssh ssh-tunnel

我正在尝试设置SSH隧道,但我是这个过程的新手。这是我的设置:

计算机B具有访问受限的Web服务。根据防火墙IP白名单,机器A已被授予访问机器B服务的权限。

我可以使用ssh连接连接到机器A.之后,我尝试从本地主机访问机器B上的Web服务,但我不能。

webservice端点如下所示: service.test.organization.com:443/org/v1/sendData

到目前为止,我已经创建了一个像这样的ssh隧道: ssh -L 1234:service.test.organization.com:443 myuser@machineb.com

我的理解是使用这种方法,我可以点击localhost:1234,它将通过机器B转发到service.test.organization.com:443。

我已经确认从机器B,我可以执行curl命令向webservice发送消息,然后我得到一个响应(这样就可以了)。我已经尝试在浏览器中使用PostMan,并从localhost卷入终端,但我没有成功。 (curl -X POST -d @test.xml localhost:1234/org/v1/sendData

错误消息:curl:(52)来自服务器的空回复

SSH上有很多材料,我正在筛选它,但如果有人有任何指示,我会非常感激!

2 个答案:

答案 0 :(得分:3)

尝试添加Host HTTP标头:curl -H "Host: service.test.organization.com" -X POST -d @test.xml http://localhost:1234/org/v1/sendData

答案 1 :(得分:0)

网络问题是由请求格式引起的。我的请求对象是使用'localhost:1234'的目标构建的。因此即使它到达了正确的机器,机器也忽略了它。

为了解决这个问题,我在主机文件中添加了一条记录,如下所示: service.test.organization.com 127.0.0.1

然后我就能发送消息了。首先,我打开隧道, ssh -L 443:service.test.organization.com:443 myuser@machineb.com, 然后使用此curl命令:curl -X POST -d @test.xml service.test.organization.com:443/org/v1/sendData

主机文件导致地址解析为localhost,然后ssh隧道知道将其转发。