Configure WEBrick to use automatically generated self-signed SSL/HTTPS certificate
Okay, I figured out what was wrong, I should've paid closer attention to the instructions for HTTPS in WEBrick, this is the exact code from the example:
require 'webrick'
require 'webrick/https' # SEE THIS?
cert_name = [
%w[CN localhost],
]
server = WEBrick::HTTPServer.new(:Port => 8000,
:SSLEnable => true,
:SSLCertName => cert_name)
See that line that says require 'webrick/https'
? I didn't have that in my original config. I didn't think that I'd need it.
Once I added it, my script started serving over HTTPS, and I could finally connect to https://localhost:4430/robots.txt
. <face-palm>
How do I configure WEBrick to use an intermediate certificate with HTTPS?
I managed to find an answer after an extra hour of googling for keywords. Here is the option to define an intermediate certificate:
:SSLExtraChainCert => [
OpenSSL::X509::Certificate.new(
File.open("certificates/intermediate.crt").read)]
Note that the option requires an Array
object, allowing to you include multiple certificates if needed.
webrick using ssl whats to do?
Most people solve this by switching from webrick to thin (or even better, unicorn/puma/passenger). I don't think webrick is designed to run in production.
You could also terminate SSL at apache so that webrick only handles http. (Also, assuming Apache is running on the same box, you don't need to bind to 0.0.0.0
. Localhost will do, and binding to an external IP sounds like a security vulnerability.)
If you really want to keep webrick and have it handle SSL, you change bin/rails
as described in this other answer.
Configuring Webrick in rails 3.0 to serve both http and https (SSL)
I solved the issue by switching Nginx but could not do it using Webrick. I guess Webrick does not support two instances of a server simultaneously and to switch you need to stop the current server and restart the server which has got https:// settings.
rails 3.2.3 doesn't work on https using webrick in ubuntu 12.0.4
The servers which you have used in dev mode doesn't seem to provide an ssl certificate to the client.
For dev purposes you can use "Thin" as it provides a ssl certificate if you start the server with the following command:
"thin start --ssl"
instead of the usual:
"rails s/rails server"
Related Topics
Detecting If This Is an Iframe Load or Direct
How to Put a Delay on a Loop in Ruby
How to Read a Gzip File Line by Line
Exec': String Contains Null Byte (Argumenterror)
Ruby Tcpsocket: Find Out How Much Data Is Available
Better Way to Write "Matching Balanced Parenthesis" Program in Ruby
Ruby Not Finding New Version of Openssl
Undefined Method Respond_To in Rails 5 Controller
How to Remove Blank Values Params from Query String
Ruby on Rails Country/State Select Enigma
Ruby Mailer Is Coming Up with an Eoferror
How to Convert Activerecord Table Name to Model Class Name
Split Seeds.Rb into Multiple Sections
Is This the Best Way to Grab Common Elements from a Hash of Arrays
Creating Spectral Heat Maps or Intensity Maps from Cdip Data Using Ruby