1

Start situation:

Installed Linux Ubuntu operating system and Ruby via apt installer. After that installed WEBrick Ruby server via gem packgake handler.

Applications with version numbers:

  • Linux Ubuntu 18.04
  • Ruby 2.5.1p57
  • OpenSSL 1.1.1
  • gem WEBrick 2.7.6
  • gem openssl 2.7.6

Target situation:

To run WEBrick server in https mode

I took a look into WEBricks homepage, where was following setup example

require 'webrick'
require 'webrick/https'
require 'openssl'

cert = OpenSSL::X509::Certificate.new File.read '/path/to/cert.pem'
pkey = OpenSSL::PKey::RSA.new File.read '/path/to/pkey.pem'

server = WEBrick::HTTPServer.new(:Port => 8000,
                                 :SSLEnable => true,
                                 :SSLCertificate => cert,
                                 :SSLPrivateKey => pkey)

trap 'INT' do server.shutdown end

server.start

I generated cert/key with the following command

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

After all, WEBrick does not work and following error message prints out

ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=error: http request
    /var/lib/gems/2.5.0/gems/webrick-1.6.0/lib/webrick/server.rb:299:in `accept'
    /var/lib/gems/2.5.0/gems/webrick-1.6.0/lib/webrick/server.rb:299:in `block (2 levels) in start_thread'

Does anyone know, how to fix the problem?

  • In ROR 5 default server is puma . You can use it with your new app executing " rails server " command in terminal . Webrick also good . If you using individual installation for ROR testing webrick is good . May be it will be something with ruby gem issue . – Kaviranga Apr 25 '20 at 11:08
  • Yes indeed. This is about plain WEBrick installation, without ROR gems. – andersville Apr 25 '20 at 11:14

1 Answers1

0

The answer can be found in the error message you receive:

ERROR OpenSSL::SSL::SSLError: SSL_accept returned=1 errno=0 state=error: http request

You are making an HTTP request, not an HTTPS request, when you attempt to visit the server. OpenSSL is expecting an HTTPS request.

Change http://localhost:8000 in your client to https://localhost:8000 and you'll get:

[2020-04-25 13:08:49] ERROR `/' not found.
::1 - - [25/Apr/2020:13:08:49 PDT] "GET / HTTP/1.1" 404 285
- -> /
anothermh
  • 9,815
  • 3
  • 33
  • 52