系统相关
首页 > 系统相关> > centos – 无法连接到端口4430上的localhost

centos – 无法连接到端口4430上的localhost

作者:互联网

我正在安装CentOS和Nginx的虚拟盒子中运行vagrant.我已经创建了从vagrant box到远程服务器的反向隧道,但是当我尝试连接到端口4430上的localhost时,我在运行命令时遇到以下错误:

curl -v 'https://localhost:4430'

* About to connect() to localhost port 4430 (#0)
*   Trying ::1... Connection refused
*   Trying 127.0.0.1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

我一直在尝试在浏览器中加载网站,但Chrome也会抛出错误.

This webpage is not available

ERR_CONNECTION_REFUSED

我想要做的是创建一个反向隧道似乎工作正常,我可以连接到远程机器并创建隧道,但我无法浏览我的本地机器上所需的(反向端口).

这是我的隧道脚本:

ssh -v -R 4430:localhost:443 user@remote-domain.com -N

有谁知道这个问题是什么?

我可以使用端口443而不是4430连接!

任何帮助,将不胜感激!

UPDATE

运行以下命令将提供以下输出

ssh -v -R 4430:localhost-domain:443 ec2-user@vm.domain.com -N

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to vm.domain.com [54.149.189.155] port 22.
debug1: Connection established.
debug1: identity file /home/vagrant/.ssh/identity type -1
debug1: identity file /home/vagrant/.ssh/identity-cert type -1
debug1: identity file /home/vagrant/.ssh/id_rsa type 1
debug1: identity file /home/vagrant/.ssh/id_rsa-cert type -1
debug1: identity file /home/vagrant/.ssh/id_dsa type -1
debug1: identity file /home/vagrant/.ssh/id_dsa-cert type -1
debug1: identity file /home/vagrant/.ssh/id_ecdsa type -1
debug1: identity file /home/vagrant/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'vm.domain.com' is known and matches the RSA host key.
debug1: Found key in /home/vagrant/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/vagrant/.ssh/identity
debug1: Offering public key: /home/vagrant/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: Local connections to LOCALHOST:4430 forwarded to remote address localhost-domain:443
debug1: Local forwarding listening on ::1 port 4430.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 4430.
debug1: channel 1: new [port listener]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.

我在想LOCALHOST:4430应该是流浪盒的主机名吗?例如,本地域名:4430

解决方法:

我认为你缺少-g选项,因为否则远程端口只会在localhost上侦听,这意味着远程localhost之外的任何其他主机都无法连接到它.

使用-g它会监听0.0.0.0,这意味着它可以在所有接口上使用,而不仅仅是localhost.

正如ssh(1)所说的g选项“允许远程主机连接到本地转发端口.如果在多路复用连接上使用,则必须在主进程上指定此选项.”

您还提到您已经在流浪盒中创建了此隧道.所以这个卷曲你的展示也在流浪盒内,对吗?否则,如果您在主机系统上运行curl而不是在无法使用的vagrant box内运行curl.如果要从主机系统(不在流浪盒内)连接到隧道,则必须连接到流浪盒的IP而不是127.0.0.1.

标签:nginx,ssl,centos,reverse-proxy,port-forwarding
来源: https://codeday.me/bug/20190816/1665400.html