title: Connection reset by peer - SSL_connect error in production when using Bitly
body: <p>I am using bitly url in my application in 2 cases. In one case I am using it through jQuery as:</p>
  
  <pre><code>  function get_short_url(long_url, login, api_key, func)
  {
      $.getJSON(
          "http://api.bitly.com/v3/shorten?callback=?", 
          { 
              "format": "json",
              "apiKey": api_key,
              "login": login,
              "longUrl": long_url
          },
          function(response)
          {
              func(response.data.url);
          }
      );
  }
  </code></pre>
  
  <p>and in other case I am using bitly gem with version 1.0.2. For this I am adding</p>
  
  <p>view:</p>
  
  <pre><code>&lt;%= f.input :link_placeholder, :as =&gt; :text, :label =&gt; false, :input_html =&gt; { :id =&gt; 'copy_link', :class =&gt; '', :value =&gt; "#{get_bitly_url(user_report_url(@user, @report))}", :rows =&gt; 2, :cols =&gt; 30, :maxlength =&gt; 490} %&gt;
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>  def show
      @report = Report.find(params[:id])
      @bitly_url = get_bitly_url("#{user_reports_url}/#{@report.id}")    
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @report }
      end
    end
    def get_bitly_url(url)
      if Rails.env.development?
        return url
      else
        bitly = Bitly.new('myapp', 'R_e2pd1dca0442a20a2qwqw59156e3260d')
        bitly.shorten(url).short_url
      end
    end
  </code></pre>
  
  <p>the above 2 are working fine in development mode and rails production mode and I also tried in AWS EC2 instance with Apache and Phusion, it is working great
    but it is not working in the main production server where the domain name is mentioned in the url with "https".</p>
  
  <p>These are the errors I am getting:</p>
  
  <blockquote>
    <p>Errno::ECONNRESET (Connection reset by peer - SSL_connect):<br>
    app/controllers/reports_controller.rb:342:in <code>get_bitly_url'<br>
    app/controllers/reports_controller.rb:35:in</code>show'</p>
  </blockquote>
  
  <p>The url mentioned in show is coming from js file as mentioned above.</p>
  
  <p>Please help me to get out of this error.</p>