上周我给小兔盒加上了https,比想象中容易许多。记录一下
免费的CA:
之前一直以为 CA 是需要每年付一笔不菲的费用的,但其实也有免费的,例如:https://www.startssl.com/
按照网站指示,可以获得由其颁发的证书?有两个文件(certification & key) 是后面工作的基础。
在开发环境中使用 https (无需nginx)
thin start --ssl --ssl-key-file YOUR_SSL_KEY_FILE --ssl-cert-file YOUR_CERT_FILE
一些 tipsurl helpers
不管当前 request 是 https 还是 http,rails 的 url_helper 都使用 http
# file: config/routes:root to: 'home#index'# in views or helpers:root_url #=> http://YOUR_SITE/root_url protocol: 'https' #=> https://YOUR_SITE/
使用 protocol 无关的 assets 地址
# file: config/environments/production.rbRails.application.configure do ... config.action_controller.asset_host = '//YOUR-CDN.com' ...end
用工具检查
有很多工具可以检查 https 部署情况,例如这个:https://www.sslshopper.com/ssl-checker.html
本文出自:http://q.pnq.cc, 原文地址:http://q.pnq.cc/blog/2014/10/13/ssl-notes-with-rails/, 感谢原作者分享。 只要有信心,人永远不会挫败