How to include SSL Certificate in Rails 3 project

。_饼干妹妹 提交于 2020-01-01 06:55:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!