rails3 ssl https
By admin
给项目的登录页面做个https认证,登录后还跳转回http的页面。
先让nginx支持ssl
在网站的配置文件中的server {…} 之前加入
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
server {} 内加入
fastcgi_param HTTPS $fastcgi_https;
参考http://www.quany.info/web-design/nginx-400-bad-request-the-plain-http-request-was-sent-to-https-port.html
其他ssl 的配置参考
http://www.linuxidc.com/Linux/2011-09/44187.htm
后来出现了400错误
The page isn’t redirecting properly
试了几回,把 server {} 里的
ssl on;
去掉就好了
只要同时 listen 80;
listen 443; 就行了
然后在程序里的验证身份中
redirect_to url_for(…., :protocol => ‘https’)
这样写,验证完的跳回80端口 :protocol => ‘http’
看rails的配置里,需要在confit/application.rb中加入
config.force_ssl = true
我加了之后出现页面循环重定向错误,后来把这个去掉了也没什么问题,觉得不用加这个。