简体   繁体   English

HTTPS 在 Ruby on rails 中的实施

[英]HTTPS implementation in Ruby on rails

I was trying to implement https on a subdomain.我试图在子域上实现 https。 I have included SSL_requriment plugin我已经包含了 SSL_requriment插件

my application controller has two statements:我的申请 controller 有两个声明:

  include SslRequirement
  ssl_required if ENV["RAILS_ENV"] == "production"

I have generated key, csr and crt and specified this in apache config file:我已经生成了密钥、csr 和 crt,并在 apache 配置文件中指定了它:

    <VirtualHost *:80>
    ServerName app.my_app.com
    DocumentRoot /home/me/my_app/production/current/public
    </VirtualHost>
    <VirtualHost *:443>
    ServerName app.my_app.com
    DocumentRoot /home/me/my_app/production/current/public
    SSLEngine on
    SSLCertificateFile /home/me/my_app/production/shared/plusrev.crt
    SSLCertificateKeyFile /home/me/my_app/production/shared/plusrev.key
    </VirtualHost>

Still my subdomain is not redirecting to https. Anything I am missing.我的子域仍然没有重定向到 https。我缺少的任何东西。

There are no actions passed to ssl_required.没有传递给 ssl_required 的操作。 However I guess you want to add但是我想你想添加

def ssl_required?
  true
end

to your controller so https is required for all actions by default.到您的 controller,因此默认情况下所有操作都需要 https。

The plugin API isn't obvious so look into the code.插件 API 并不明显,因此请查看代码。

Here is the solution.这是解决方案。

Use采用

 gem 'grosser-ssl_requirement', :require => 'ssl_requirement'

in you gemFile.在你的 gemFile. Here is the gem guide这是宝石指南

In your application controller:在您的申请 controller 中:

 include SslRequirement
 ssl_required :all if ENV["RAILS_ENV"] == "production"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM