我的 nginx.conf 中的服务器声明:
    listen       1.2.3.4:443 ssl;
    root /var/www/myapp/current/public;
    ssl on;
    ssl_certificate /etc/nginx-cert/server.crt;
    ssl_certificate_key /etc/nginx-cert/server.key;
    location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          if (!-f $request_filename) {
            proxy_pass http://upstreamy;
            break;
          }
     }
nginx.conf 中的上游声明:
upstream upstreamy {
    server unix:/var/www//myapp/shared/sockets/unicorn.sock fail_timeout=0;
}
这很好用,myapp 可以通过https://somehost访问
但是该应用程序正在为重定向生成 http url,因此例如在使用devise 进行身份验证时,/ 被重定向到 http://somehost/user/sign_in而不是 https(从 rails 应用程序的角度来看,无论如何都是 http)。
我试过
proxy_pass https://upstreamy;
但这只是试图加密 nginx 和运行 rails 应用程序的独角兽之间的流量。
我也尝试过,在 application_helper.rb 中:
# http://stackoverflow.com/questions/1662262/rails-redirect-with-https
def url_options
  super
  @_url_options.dup.tap do |options|
  options[:protocol] = Rails.env.production? ? "https://" : "http://"
  options.freeze
end
但它似乎不起作用。
如何解决这个问题?
编辑:所以,目标不是让rails应用程序需要ssl,或者被迫使用ssl;目标是让 Rails 应用程序在重定向时生成 https:// url...(我认为所有其他 url 都是相对的)。