问题
I have developed a Rails 3 project which uses thin
as server, along with Devise and Doorkeeper for Authentication
I would like to add SSL Certificate in my project. I have seen some posts which describes how to use SSL Certificate in Rails 3 Project,but none of then showing how to add certificate in Rails 3 project.
I have enabled config.force_ssl = true
in my applicationcontroller.rb
, and I tried starting thin server like:
thin start --ssl
It works without adding certificate and I can now access my website with https://
(Getting Certificate not verified Warning from Browser. I hope this is because my certificate is not verified by CA).
Recently I have seen a post showing how to add SSL Certificate in Rails 3 project; How can I pass SSL options into "rails server" in Rails 3.0?
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open(current_dir + "/config/certs/server.key").read),
:SSLCertificate => OpenSSL::X509::Certificate.new(File.open(current_dir + "/config/certs/server.crt").read),
:SSLCertName => [ [ "CN", WEBrick::Utils::getservername ] ]
Is this the right way of adding the certificate? Each time when I try to start the server I need to specify these options.
Is there any other method to include certificate path in my project config (or include certificate in my project) so that there is no need for specifying certificate path each and every time I start my server?
Any help is appreciated....
回答1:
Here I found answer about adding ssl to thin:
Thin with SSL support and ruby-debug
If you want to add ssl to nginx (I advice to use nginx in production) here is described how to add certificate to nginx
http://wiki.nginx.org/HttpSslModule
server {
listen 443;
ssl on;
ssl_certificate /path_to_certificate/cert.pem;
ssl_certificate_key /path_to_certificate/cert.key;
keepalive_timeout 70;
}
来源:https://stackoverflow.com/questions/14681797/how-to-include-ssl-certificate-in-rails-3-project