title: ERR_CONNECTION_RESET while using localhost
body: <p>I am new to backend development. I am working on creating a basic webserver using vagrant and virtualbox. Agter running the server from the VM, when I try to reach it from the host machine, I get the above error.</p>
  
  <p>Following is the vagrant configuration:</p>
  
  <pre><code>Vagrant.configure(2) do |config|
    config.vm.box = "ubuntu/trusty32"
    config.vm.network "forwarded_port", guest: 80, host: 8080
  end
  </code></pre>
  
  <p>Following is the main() code in the server file:</p>
  
  <pre><code>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()   
  </code></pre>
  
  <p>After reading a lot about it, I tried some ways to make it work but to no avail.
  Also <code>telnet localhost 8080</code> on the host machine gives:</p>
  
  <pre><code>Trying 127.0.0.1...
  Connected to localhost.
  Escape character is '^]'.
  Connection closed by foreign host.
  </code></pre>
  
  <p>Running vagrant up shows that it is forwarding port from 80(guest) to 8080(host). But running <code>sudo netstat -ntlp | grep LISTEN</code> on the VM gives:</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>Running <code>curl -v 'http://localhost:8080'</code> gives:</p>
  
  <pre><code>*   Trying 127.0.0.1...
  * Connected to localhost (127.0.0.1) port 8080 (#0)
  &gt; GET / HTTP/1.1
  &gt; Host: localhost:8080
  &gt; User-Agent: curl/7.47.0
  &gt; Accept: */*
  &gt; 
  * Recv failure: Connection reset by peer
  * Closing connection 0
  curl: (56) Recv failure: Connection reset by peer
  </code></pre>
  
  <p>Running <code>curl 'http://localhost:80'</code> on the VM gives:</p>
  
  <pre><code>curl: (7) couldn't connect to host
  </code></pre>
  
  <p>This is output when I run <code>vagrant up</code>:</p>
  
  <pre><code>==&gt; default: Preparing network interfaces based on configuration...
      default: Adapter 1: nat
  ==&gt; default: Forwarding ports...
      default: 80 (guest) =&gt; 8080 (host) (adapter 1)
      default: 22 (guest) =&gt; 2222 (host) (adapter 1)
  ==&gt; default: Booting VM...
  ==&gt; 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
  ==&gt; default: Machine booted and ready!
  ==&gt; 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
  ==&gt; default: Mounting shared folders...
      default: /vagrant =&gt; /home/priyanshu/fullstack
  ==&gt; default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
  ==&gt; default: flag to force provisioning. Provisioners marked to run always will still run
  </code></pre>
  
  <p>I am completely new to this. Let me know what am I doing wrong here.</p>