Passenger,nginx and SSL(http redirect to https)
2012-05-16 14:52
435 查看
参见配置SSL
Nginx + https + 免费SSL证书配置指南
但是配置完后,rails中的request.ssl? 永远返回false
Passenger 3 implements this feature with a new directive
For example, to pass SSL variables to Rack, you could do this:
然后重写Rack::Request.scheme方法:
在ApplicationController中添加代码
此时的request.ssl?就生效了
Nginx + https + 免费SSL证书配置指南
但是配置完后,rails中的request.ssl? 永远返回falsePassenger 3 implements this feature with a new directive
passenger_set_cgi_paramwhich behaves like
proxy_set_header.
For example, to pass SSL variables to Rack, you could do this:
server { listen 443 default ssl; # other SSL stuff goes here # other passenger stuff here passenger_set_cgi_param X_FORWARDED_PROTO https; passenger_set_cgi_param X-SSL-Raw-Cert $ssl_client_raw_cert; passenger_set_cgi_param X-SSL-Cert $ssl_client_cert; passenger_set_cgi_param X-SSL-Client-S-DN $ssl_client_s_dn; passenger_set_cgi_param X-SSL-Client-I-DN $ssl_client_i_dn; passenger_set_cgi_param X-SSL-Client-Verify $ssl_client_verify; }
然后重写Rack::Request.scheme方法:
module Rack class Request def scheme if self.headers['X_FORWARDED_PROTO'].eql?("https") 'https' elsif @env['HTTPS'] == 'on' 'https' elsif @env['HTTP_X_FORWARDED_SSL'] == 'on' 'https' elsif @env['HTTP_X_FORWARDED_PROTO'] @env['HTTP_X_FORWARDED_PROTO'].split(',')[0] else @env["rack.url_scheme"] end end end end
在ApplicationController中添加代码
class ApplicationController < ActionController::Base before_filter :redirect_to_https def redirect_to_https unless(request.ssl?) redirect_to :protocol=>"https://" return end end end
此时的request.ssl?就生效了
相关文章推荐
- Redirect all HTTP requests to HTTPS with Nginx
- Failed to fetch URL https://dl-ssl.google.com/android/repository/repository-10.xml, reason: HttpHost
- Nginx:The plain HTTP request was sent to HTTPS port解决办法
- nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port
- //dl-ssl.google.com/android/repository/repository-8.xml, reason: HttpHostConnect Connection to https
- IIS 7.x or higher version HTTP redirect to HTTPS
- Configuration to access by HTTPS with SSL in Apache HTTP
- nginx: 400 Bad Request | The plain HTTP request was sent to HTTPS port
- 服务器 nginx配置ssl并http重定向到https
- IIS7 Redirect HTTP to HTTPS
- Nginx配置SSL并强制http跳转到https
- weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- HttpClient post parameters to Https(避免ssl错误)
- nginx配置将http请求转发支持ssl双向认证https请求的正向代理
- Redirect HTTP to HTTPS on Tomcat
- Nginx Tomcat http 强制跳转https ssl crt key
- nginx 代理https后,应用redirect https变成http --转
- 微信开发:weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
- Android WebView blocks redirect from https to http
- Nginx 配置https 开启ssl 同时支持http