ERR_CONNECTION_RESET 使用本地主机时
ERR_CONNECTION_RESET while using localhost
我是后端开发新手。我正在使用 vagrant 和 virtualbox 创建一个基本的网络服务器。 运行从 VM 连接服务器后,当我尝试从主机访问它时,出现上述错误。
以下是 vagrant 配置:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
服务器文件中的main()代码如下:
def main():
try:
port = 8080
server = HTTPServer(('', port), webserverHandler)
print "Web server running on port %s" % port
server.serve_forever()
except KeyboardInterrupt:
print "^C entered. Shutting down the server..."
server.socket.close()
在阅读了很多有关它的资料后,我尝试了一些方法让它工作但无济于事。
主机上的 telnet localhost 8080
也给出:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
运行 vagrant up 显示它正在将端口从 80(来宾)转发到 8080(主机)。但是 VM 上的 运行ning sudo netstat -ntlp | grep LISTEN
给出:
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 491/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 685/sshd
tcp 0 0 0.0.0.0:52166 0.0.0.0:* LISTEN 649/rpc.statd
tcp6 0 0 :::57101 :::* LISTEN 649/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 491/rpcbind
tcp6 0 0 :::22 :::* LISTEN 685/sshd
运行 curl -v 'http://localhost:8080'
给出:
* 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.47.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
运行 curl 'http://localhost:80'
在 VM 上给出:
curl: (7) couldn't connect to host
这是我运行vagrant up
:
时的输出
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => /home/priyanshu/fullstack
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run
我对此完全陌生。让我知道我在这里做错了什么。
您的 python 服务器 运行 在端口 8080
上,运行 端口 80 没有任何内容(如 netstat 命令的输出所示)
在您的情况下,您需要将来宾端口更改为来自您的 python 服务器
的端口
config.vm.network "forwarded_port", guest: 8080, host: 8080
我是后端开发新手。我正在使用 vagrant 和 virtualbox 创建一个基本的网络服务器。 运行从 VM 连接服务器后,当我尝试从主机访问它时,出现上述错误。
以下是 vagrant 配置:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
服务器文件中的main()代码如下:
def main():
try:
port = 8080
server = HTTPServer(('', port), webserverHandler)
print "Web server running on port %s" % port
server.serve_forever()
except KeyboardInterrupt:
print "^C entered. Shutting down the server..."
server.socket.close()
在阅读了很多有关它的资料后,我尝试了一些方法让它工作但无济于事。
主机上的 telnet localhost 8080
也给出:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
运行 vagrant up 显示它正在将端口从 80(来宾)转发到 8080(主机)。但是 VM 上的 运行ning sudo netstat -ntlp | grep LISTEN
给出:
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 491/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 685/sshd
tcp 0 0 0.0.0.0:52166 0.0.0.0:* LISTEN 649/rpc.statd
tcp6 0 0 :::57101 :::* LISTEN 649/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 491/rpcbind
tcp6 0 0 :::22 :::* LISTEN 685/sshd
运行 curl -v 'http://localhost:8080'
给出:
* 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.47.0
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
运行 curl 'http://localhost:80'
在 VM 上给出:
curl: (7) couldn't connect to host
这是我运行vagrant up
:
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 80 (guest) => 8080 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => /home/priyanshu/fullstack
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run
我对此完全陌生。让我知道我在这里做错了什么。
您的 python 服务器 运行 在端口 8080
上,运行 端口 80 没有任何内容(如 netstat 命令的输出所示)
在您的情况下,您需要将来宾端口更改为来自您的 python 服务器
的端口config.vm.network "forwarded_port", guest: 8080, host: 8080