使用Ruby on Rails进行SSL [英] SSL with Ruby on Rails
问题描述
我需要做些什么来获取我的ruby on rails app上的流量才能使用https?我安装了证书,如果我在访问网站时在地址栏中手动输入https://,则会出现小锁图标,但只需在浏览器中手动转到www.example-app.com即可通过http发送流量://。
What do I need to do to get traffic to my ruby on rails app to use https? I have a certificate installed and if I manually type in "https://" in the address bar when accessing the site the little lock icon appears, but just manually going to www.example-app.com in my browser sends traffic through http://.
是否有一些单线配置还是比这更复杂?我以前从来没有处理过SSL,所以请原谅我,如果我听起来不知道发生了什么。
Is there some one-line config or is it more complicated than that? I've never had to deal with SSL before, so excuse me if I sound like I don't know what's going on.
我在MediaTemple中主持一个(gs),如果重要或任何人都有这种设置的经验。
I'm hosting at MediaTemple in a (gs), if that matters or anyone has experience with such a setup.
推荐答案
查看 ssl_requirement gem。
它允许您在控制器中指定哪些操作应通过https提供服务,以及可以通过https提供哪些操作。然后它将处理从http重定向到https,反之亦然。
It lets you specify in your controllers which actions should be served over https and which actions can be served over https. It will then take care of redirecting from http to https and vice-versa.
来自文档:
class ApplicationController < ActiveRecord::Base
include SslRequirement
end
class AccountController < ApplicationController
ssl_required :signup, :payment
ssl_allowed :index
def signup
# Non-SSL access will be redirected to SSL
end
def payment
# Non-SSL access will be redirected to SSL
end
def index
# This action will work either with or without SSL
end
def other
# SSL access will be redirected to non-SSL
end
end
这篇关于使用Ruby on Rails进行SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!