Curl 使用本地主机时连接重置出错

Curl 使用本地主机时连接重置出错,curl,server,vagrant,localhost,virtualbox,Curl,Server,Vagrant,Localhost,Virtualbox,我是后端开发新手。我正在使用vagrant和virtualbox创建一个基本的Web服务器。Agter从VM运行服务器时,当我试图从主机访问服务器时,会出现上述错误 以下是流浪者的配置: Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty32" config.vm.network "forwarded_port", guest: 80, host: 8080 end 以下是服务器文件中的主要代码: def ma

我是后端开发新手。我正在使用vagrant和virtualbox创建一个基本的Web服务器。Agter从VM运行服务器时,当我试图从主机访问服务器时,会出现上述错误

以下是流浪者的配置:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty32"
  config.vm.network "forwarded_port", guest: 80, host: 8080
end
以下是服务器文件中的主要代码:

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显示它正在将端口从80guest转发到80Host。但是在虚拟机上运行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: (7) couldn't connect to host
运行curl-v'http://localhost:8080“提供:

跑步卷发'http://localhost:80“在虚拟机上提供:

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: (7) couldn't connect to host
这是我运行vagrant up时的输出:


我对这个完全陌生。让我知道我在这里做错了什么。

您的python服务器在端口8080上运行,而没有任何东西在端口80上运行,正如netstat命令的输出所示

在您的情况下,需要将来宾端口更改为python服务器上的端口

config.vm.network "forwarded_port", guest: 8080, host: 8080

您的虚拟机在端口80上没有运行任何东西,您需要启动apache或nginx。python服务器正在8080端口上运行,您是否启动了它?我的错。将文件中的来宾端口更改为8080。现在可以了。谢谢