title: https redirect for rails app behind proxy?
body: <p>server declaration in my nginx.conf:</p>
  
  <pre><code>    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;
            }
       }
  </code></pre>
  
  <p>upstream declaration in nginx.conf:</p>
  
  <pre><code>upstream upstreamy {
      server unix:/var/www//myapp/shared/sockets/unicorn.sock fail_timeout=0;
  }
  </code></pre>
  
  <p>this works fine, myapp is reachable as <a href="https://somehost">https://somehost</a></p>
  
  <p>but the app is generating http url's for redirects, so for instance when authenticating with devise, the / is redirected to <a href="http://somehost/user/sign_in">http://somehost/user/sign_in</a> instead of https (from the viewpoint of the rails app, it's all http anyway).</p>
  
  <p>I tried</p>
  
  <pre><code>proxy_pass https://upstreamy;
  </code></pre>
  
  <p>but that just tries to encrypt traffic between nginx and the unicorns that run the rails app. </p>
  
  <p>I also tried, in application_helper.rb:</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>but it seems to not work.</p>
  
  <p>How would one solve this?</p>
  
  <p>Edit: so, the goal is not to make the rails app to require ssl, or to be forced to use ssl; the goal is to make the rails app generate https:// urls when redirecting... (I think all other urls are relative).</p>