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.
Ruby on Rails WEBrick SSL connection error
According to this:
How to use deactivate Webrick's SSL
The issue is caused by config.force_ssl = true
. Even if you remove that, which you may not want, you might still have issues with WEBrick giving you this error. You could try clearing cookies, but that still might not work.
A better alternative, if it's an option for you, would be to switch to using the thin server:
group :development do
gem "thin"
end
Then:
$ bundle
$ thin start --ssl
See also https://stackoverflow.com/a/11614213
Related Topics
How to Implement Enums in Ruby
Disable Activerecord For Rails 4
In Ruby on Rails, to Extend the String Class, Where Should the Code Be Put In
How to Get Argument Names Using Reflection
Using Sinatra For Larger Projects Via Multiple Files
Ruby Function to Remove All White Spaces
Save Image from Url by Paperclip
How to Split (Chunk) a Ruby Array into Parts of X Elements
How Does Instance_Eval Work and Why Does Dhh Hate It
Ruby: Kind_Of? Vs. Instance_Of? Vs. Is_A
Why Does Installing Nokogiri on MAC Os Fail With Libiconv Is Missing
Tzinfo::Datasourcenotfound Error Starting Rails V4.1.0 Server on Windows
Converting a Nested Hash into a Flat Hash