Passenger,nginx and SSL(http redirect to https)
来源:互联网 发布:怎么用ps做淘宝主图 编辑:程序博客网 时间:2024/05/10 15:31
参见配置SSL
Nginx + https + 免费SSL证书配置指南
但是配置完后,rails中的request.ssl? 永远返回false
Passenger 3 implements this feature with a new directive passenger_set_cgi_param
which behaves likeproxy_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 endend
在ApplicationController中添加代码
class ApplicationController < ActionController::Base before_filter :redirect_to_https def redirect_to_https unless(request.ssl?) redirect_to :protocol=>"https://" return end endend
此时的request.ssl?就生效了
- Passenger,nginx and SSL(http redirect to https)
- Redirect http to https
- Redirect all HTTP requests to HTTPS with Nginx
- Nginx+Tomcat+SSL 识别 https还是http
- nginx+ssl配置http和https共存
- Nginx+Tomcat 7 to support SSL(HTTPS)
- nginx SSl redirect问题
- 监测HTTP and SSL / HTTPS 的工具
- nginx ssl tomcat no ssl https http问题
- Android WebView blocks redirect from https to http
- rails+apache2+passenger+ssl实现https双向认证通信
- nginx 代理https后,spring mvc web应用redirect https变成http
- Nginx配置SSL并强制http跳转到https
- nginx配置ssl证书实现https和http共存访问
- Nginx添加SSL证书并设置自动http转换HTTPS
- Nginx Tomcat http 强制跳转https ssl crt key
- Nginx环境下http和https(ssl)共存的方法
- 服务器 nginx配置ssl并http重定向到https
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](四) 之 使用swftools将pdf转换为swf
- 使用SVG内置API计算图形或点经过transform之后的新坐标
- How to troubleshoot memory problems
- 設定 Git 環境
- Windows Server appfabric exception ErrorCode<ERRCA0016>:SubStatus<ES0001>
- Passenger,nginx and SSL(http redirect to https)
- FFT结果的物理意义
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](五) 之 转换pdf的同时,进一步转为swf
- MFC串行化(即序列化Serialization)
- 关于ArcGIS Server Flex API中QueryTask报"#2032流错误"的解决
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](六) 之 flexpaper在线浏览swf文档
- Linux 文件系统结构详解
- android输入法01:SoftKeyboard源码解析03
- 软件随想--写牛B的代码