0

How do I get Ruby On Rails Webrick to work with self-signed SSL certificate on localhost just to test https ? Basically, Ived followed the work that has been done here: Configure WEBrick to use automatically generated self-signed SSL/HTTPS certificate

And produce the script like the following:

require 'webrick'
require 'webrick/https'

cert_name = [
  %w[CN localhost],
]

server = WEBrick::HTTPServer.new(:Port => 8000,
                                 :SSLEnable => true,
                                 :SSLCertName => cert_name)


# Shutdown gracefully on signal interrupt CTRL-C
# http://www.ruby-doc.org/core-2.1.1/Kernel.html#method-i-trap
trap('INT') { server.shutdown }

server.start

When I tried to access https://localhost:8000/, it did warn about trust but just went ahead, instead I had nothing come out but this. BTW, https works fine, just it seems its not getting the right route for SSL.

Not Found

`/' not found.
WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08) OpenSSL/1.0.2 at localhost:8000

console prints this:

[2015-07-25 23:38:25] INFO  WEBrick::HTTPServer#start: pid=6765 port=8000
[2015-07-25 23:38:32] ERROR `/' not found.
localhost - - [25/Jul/2015:23:38:32 MYT] "GET / HTTP/1.1" 404 284
- -> /
Community
  • 1
  • 1
Axil
  • 3,606
  • 10
  • 62
  • 136

1 Answers1

1

The reason your server is returning that 404 is because the script you've set up is just for an empty WEBrick server; it doesn't actually mount your Rails app. The thread you linked to seemed to be using that script just as a minimal test for the SSL functionality. The full answer to getting WEBrick to work with SSL looks to be answered here: How do you configure WEBrick to use SSL in Rails?

However, I wouldn't recommend you bother. WEBrick is strictly meant as a development-only server, and isn't suitable for use in production (which is why it's hard to get it to do things like use SSL). Instead, either set up nginx as a SSL-serving proxy to your app or use a server which supports SSL easily, like thin does.

Community
  • 1
  • 1
Robert Nubel
  • 7,104
  • 1
  • 18
  • 30