title: Errno::ECONNREFUSED: Connection refused - connect(2) with Net::HTTP
body: <p>I have my one server connecting to my other server (on a different machine) using net::http. When I use curl, it works (on localhost):</p>
  
  <pre><code>curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"user":{"email":"info@mysite.com","password":"password"}}' http://mysite.com:80/pages/account_stuff.json
  =&gt; {"account_id":4,"account_name":"Some Name","status":200}
  </code></pre>
  
  <p>On localhost, everything works fine. On one of my servers, a totally different scenerio.</p>
  
  <p>When I use net::http on my ubuntu server, I get the Errno::ECONNREFUSED: Connection refused - connect(2):</p>
  
  <pre><code>url = "http://mysite.com:80/pages/account_stuff.json"
  @uri = URI.parse(url)
  @body = {"user" =&gt; {"email" =&gt; "info@mysite.com", "password" =&gt; "password"}}.to_json
  @headers = {'Content-Type' =&gt; 'application/json'}
  req = Net::HTTP::Post.new(@uri.to_s, initheader = @headers)
  req.body = @body
  http = Net::HTTP.new(@uri.host,@uri.port).start
  Errno::ECONNREFUSED: Connection refused - connect(2)
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `open'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:762:in `connect'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
      from /usr/local/rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:750:in `start'
      from (irb):17
      from /home/mysite/public_html/store.mysite.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
      from /home/mysite/public_html/store.mysite.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
      from /home/mysite/public_html/store.mysite.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `&lt;top (required)&gt;'
      from script/rails:6:in `require'
      from script/rails:6:in `&lt;main&gt;'
  </code></pre>
  
  <p>Tried other post technique:</p>
  
  <pre><code>uri = URI.parse('http://mysite.com/pages/account_stuff.json')
  res = Net::HTTP.post_form(uri, {"user" =&gt; {"email" =&gt; "info@mysite.com", "password" =&gt; "password"}})
  Errno::ECONNREFUSED: Connection refused - connect(2)
  </code></pre>
  
  <p>Then tried net::http get request:</p>
  
  <pre><code>uri = URI('http://mysite.com/pages/account_stuff')
  Net::HTTP.get(uri)
  Errno::ECONNREFUSED: Connection refused - connect(2)
  </code></pre>
  
  <p>Then dropped net::http and tried with open::uri instead:</p>
  
  <pre><code>open("http://mysite.com")
  Errno::ECONNREFUSED: Connection refused - connect(2)
  </code></pre>
  
  <p>Getting desperate now, tried  a basic curl request:</p>
  
  <pre><code>curl http://mysite.com
  curl: (7) couldn't connect to host
  </code></pre>
  
  <p>Obviously, I realize this is no longer a ruby issue, and definitely not a curl issue. There must be some sort of firewall blocking traffic to the machine that server is on. I can connect to google just fine with curl but not that site.</p>