通过 gem 与 Apache 级别的 Rails SSL 重定向
我正在研究实施 SSL 来保护我的 Rails 应用程序的最佳方法。今天的建议似乎是始终使用 SSL。目前似乎有两种方法可以做到这一点:
使用诸如 Rack::SSL 或 Rack::SslEnforcer 之类的 gem,详细讨论如下: http://collectiveidea.com/blog/archives/2010 /11/29/ssl-with-rails/
在网络服务器级别重定向,推荐此处: Rails + SSL:每个控制器还是应用程序范围?
确信 Apache 级别的重定向(假设正在运行 Apache)必须是一种可行的方法,既可以简化实现,又可以提高性能。
我不明白也没有看到解决的是为什么有这么多的精力和注意力投入到使用 gems 在应用程序层做这件事?甚至有来自 DHH 的评论(上面第一个链接中的最后一条评论)指出“Rails 3.1 现在将在应用程序和控制器级别内置force_ssl。”那么我错过了什么?
为什么人们会选择使用其中一种宝石来一直使用 SSL?
I'm researching the best approach for implementing SSL to secure my rails app. The recommendation of the day seems to be to use SSL all the time. There seem to be two current ways of doing it:
Use a gem such as Rack::SSL or Rack::SslEnforcer, discussed in detail here:
http://collectiveidea.com/blog/archives/2010/11/29/ssl-with-rails/Redirect at the webserver level, recommended here:
Rails + SSL: Per controller or application-wide?
I'm convinced that redirecting at the Apache level (assuming one is running Apache) must be the way to go, both to simplify implementation and performance.
What I don't understand and haven't seen addressed is why there is so much effort and attention devoted to doing it at the application layer using gems? There is even a comment from DHH (last comment in first link above) stating "Rails 3.1 will now have force_ssl baked in at both the app and controller level." So what am I missing?
Why would one choose to use one of the gems to use SSL all the time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一,这是 Rails 社区很容易接受的标准。现在,每当您想要 Rails 应用程序需要 https 时,您都可以翻转这个开关,无论您使用什么服务器或其他架构,它都可以工作。
第二,如果您使用 Heroku 等托管服务,则无论如何您都无权访问服务器配置设置。
One, it's an easy standard for the Rails community to settle on. Now, whenever you want to require https for a Rails app, you can flip this single switch, and it'll work regardless of what server or other architecture you might be using.
Two, if you're on a hosting service like Heroku, you won't have access to server configuration settings anyway.
force_ssl 是 Rails 3 中添加的一个配置属性。它使应用程序使用 Rack::SSL 中间件。
参考: http://edgeguides.rubyonrails.org/configuring.html
所以 config.force_ssl 是方便,让您避免弄乱机架堆栈;它已经为你做好了。
在Rails 2.X应用程序中,您不会有force_ssl,并且必须自己注入Rack::SSL或Rack::SslEnforcer。
force_ssl is a config property added to Rails 3. It makes the app use the Rack::SSL middleware.
reference: http://edgeguides.rubyonrails.org/configuring.html
So config.force_ssl is a convenience that lets you avoid messing with the Rack stack; it's done for you.
In Rails 2.X apps you would not have force_ssl and would have to inject Rack::SSL or Rack::SslEnforcer yourself.