如何在 Rails 3 项目中包含 SSL 证书 [英] How to include SSL Certificate in Rails 3 project

查看:52
本文介绍了如何在 Rails 3 项目中包含 SSL 证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 Rails 3 项目,它使用 thin 作为服务器,以及 Devise 和 Doorkeeper 进行身份验证

I have developed a Rails 3 project which uses thin as server, along with Devise and Doorkeeper for Authentication

我想在我的项目中添加 SSL 证书.我看过一些帖子描述了如何在 Rails 3 项目中使用 SSL 证书,但没有一个展示如何在 Rails 3 项目中添加证书.

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.

我在我的 applicationcontroller.rb 中启用了 config.force_ssl = true,并且我尝试启动瘦服务器,如:

I have enabled config.force_ssl = true in my applicationcontroller.rb, and I tried starting thin server like:

thin start --ssl

它无需添加证书即可工作,我现在可以使用 https:// 访问我的网站(从浏览器获取证书未验证警告.我希望这是因为我的证书未经 CA 验证).

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).

最近我看到一个帖子,展示了如何在 Rails 3 项目中添加 SSL 证书;如何才能我将 SSL 选项传递给rails server"在 Rails 3.0 中?

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?

感谢任何帮助....

推荐答案

在这里我找到了关于将 ssl 添加到 Thin 的答案:

Here I found answer about adding ssl to thin:

精简,支持 SSL 和 ruby​​-debug

如果你想将 ssl 添加到 nginx(我建议在生产中使用 nginx)这里描述了如何将证书添加到 nginx

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;
}

这篇关于如何在 Rails 3 项目中包含 SSL 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆