我有几个 shh 隧道指向不同的“remotes_servers”(不同的域),如下所示:
ssh -fN -L local_port:remote_server:remote_port user@gateway
因此,在我的本地计算机中
localhost:local_port
指向 remote_server:remote_port
,问题是某些 remote_server
需要自定义 CA 证书。
当我尝试做类似的事情时:
curl --cacert CA.pem https://localhost:local_port
我有一个错误“没有替代证书主题名称与目标主机名'localhost'匹配”,这是真的,因为我指向
localhost
而不是remote_server
可以使用
--insecure
中的 curl
、--config http.sslVerify=false
中的 git
等建立连接。我想避免这种类型的方法。
我想找到一种方法来表明,在客户端,
localhost:local_port
两者(不仅仅是localhost
)与remote_server:remote_port
相同,我还有其他端口指向不同的remote servers
,始终使用localhost
.
您可以编辑 /etc/hosts 文件,以便
remote_server
实际上映射到 localhost
(然后将浏览器指向 https://remote_server:local_port
)。
也就是说,如果我更新我的
/etc/hosts
文件,这样我就有:
127.0.0.1 localhost localhost.localdomain google.com mentos.com
我设置了 SSH 端口转发,例如:
ssh -L 8443:google.com:443 -L 8444:mentos.com:443 some.remote.server
然后运行没有错误:
curl https://google.com:8443
正如:
curl https://mentos.com:8444
不要使用
https://localhost
。相反,请在地址中使用远程主机名,并使用 --connect-to
参数,如下所示:
curl \
--cacert CA.pem \
--connect-to localhost:local_port \
https://remote_server:remote_port/
这样,
remote_server
的名称将在 SNI 协商期间指定(让服务器选择正确的证书(如果有多个证书可供选择))并在 TLS 证书验证期间进行验证。