2017-05-31 39 views
0

私はバックエンド開発を初めて行っています。 vagrantとvirtualboxを使って基本的なWebサーバーを作成しています。私はホストマシンからそれに到達しようとすると、VMからサーバーを実行している、私は上記のエラーが表示されます。ローカルホストを使用中のERR_CONNECTION_RESET

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. 

を放浪を実行することが8080(ホスト)へ80(ゲスト)からポートを転送していることを示しています。しかし、VM上で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'を実行すると得られます。VM上curl 'http://localhost:80'を実行

* 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: (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 

私は全く新しいです。ここで間違っていることを教えてください。

+0

あなたのVMでポート80で何も実行していない場合は、apacheまたはnginxを起動する必要があります。 Pythonサーバーはポート8080で動作していますが、起動していますか? –

+0

私の悪いです。 vagrantfileのゲストポートを8080に変更しました。それは今働く。ありがとう! –

答えて

1

はあなたのpythonサーバーはポート8080上で実行されていると、あなたのpythonのサーバー

から1へのゲストポートを変更する必要がありますあなたの場合は

(netstatコマンド番組の出力として)何もポート80を実行されていません

config.vm.network "forwarded_port", guest: 8080, host: 8080 
関連する問題