title: SSL with Puma, HTTP parse error, malformed request
body: <p>Attempting to configure Puma with HTTPS for a rails application being served in a private network on a remote server.  <a href="https://www.rubydoc.info/gems/puma#Binding_TCP___Sockets" rel="nofollow noreferrer">Puma Docs</a> make it look like it is possible, and they provide this command:</p>
  
  <pre><code>puma -b 'ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert'
  </code></pre>
  
  <p>Steps taken (for testing purposes):</p>
  
  <p><strong>Generate private key and self-signed certificate</strong></p>
  
  <pre><code>openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/puma_test.key -out /etc/zzz_puma_test.crt
  </code></pre>
  
  <p><br></p>
  
  <p><strong>Boot up Puma</strong></p>
  
  <pre><code>rvmsudo rails s -p 443 -b 'ssl://127.0.0.1?key=/etc/puma_test.key&amp;cert=/etc/zzz_puma_test.crt'
  </code></pre>
  
  <p><br></p>
  
  <p>When I boot up the server, in the logs I see this which I think is odd: <code>Listening on tcp://0.0.0.0:443</code>  It is like Puma is still booting up in http as opposed to https.  Here is terminal logs in its entirety when booting up puma:</p>
  
  <pre><code>=&gt; Booting Puma
  =&gt; Rails 4.2.8 application starting in development on http://ssl://127.0.0.1?key=/etc/puma_test.key&amp;cert=/etc/zzz_puma_test.crt:443
  =&gt; Run `rails server -h` for more startup options
  =&gt; Ctrl-C to shutdown server
  Puma starting in single mode...
  * Version 3.12.0 (ruby 2.3.3-p222), codename: Llamas in Pajamas
  * Min threads: 0, max threads: 16
  * Environment: development
  * Listening on tcp://0.0.0.0:443
  </code></pre>
  
  <p>When I attempt to access the site, I get this error in terminal:</p>
  
  <blockquote>
    <p>HTTP parse error, malformed request (): #Puma::HttpParserError: Invalid HTTP format, parsing fails.</p>
  </blockquote>
  
  <p>In the firefox browser itself, it provides this feedback:</p>
  
  <blockquote>
    <p>SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG</p>
  </blockquote>
  
  <p>What is odd is that I do the exact steps above locally on my computer, for an app being served locally on my computer, and it all works fine.  </p>
  
  <ul>
  <li>I created a new app</li>
  <li>Ran the above line to generate the secret key and the self-signed certificate</li>
  <li>Ran the above line to boot up the server</li>
  <li>In terminal when the server is booted up, it shows it is listening properly (in other words: never mentions http): <code>Listening on ssl://127.0.0.1:443?key...cert...</code></li>
  <li>Connecting to <code>https://localhost/blogs</code> works just fine.</li>
  </ul>
  
  <p>Perhaps it has something to do with the fact that I am using linux machine as opposed to my mac?  Or, perhaps it is that my testing app lives on a remote server in my network? I looked at the method that generates this error.  It is <a href="https://github.com/puma/puma/blob/master/lib/puma/events.rb" rel="nofollow noreferrer">parse_error, line 95 of events.rb</a>.   </p>
  
  <p>Resources already looked at:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/16063117/how-to-configure-rails-with-puma-to-use-ssl">SO Post</a></li>
  <li><a href="https://gist.github.com/tadast/9932075" rel="nofollow noreferrer">GithubGist</a></li>
  <li><a href="https://github.com/gbarillot/rails-vue-demo-app/issues/12" rel="nofollow noreferrer">Open Issue</a>, <a href="https://github.com/puma/puma/issues/986" rel="nofollow noreferrer">closed issue</a>, </li>
  </ul>
  
  <p>I have tried tweaking the <code>rails s</code> command above with a number of different small changes:</p>
  
  <ul>
  <li>changed IP from <code>127.0.0.1</code> to <code>0.0.0.0</code></li>
  <li>do not specify the <code>-p 443</code> option</li>
  <li>specify the actual, internal IP address instead of <code>127.0.0.1</code> (this is being served on an internal network)</li>
  </ul>
  
  <p>I have also tried deleting my browsing history, and tried accessing the site from multiple browsers. </p>
  
  <p>Any help is appreciated, thanks!</p>