https redirect for rails app behind proxy?

后端 未结 2 498
野的像风
野的像风 2020-12-15 05:59

server declaration in my nginx.conf:

    listen       1.2.3.4:443 ssl;
    root /var/www/myapp/current/public;
    ssl on;
    ssl_certificate /etc/nginx-cer         


        
相关标签:
2条回答
  • 2020-12-15 06:26

    You can pass :protocol => "https", to redirect_to.

    You can set this as a default by adding the following to application.rb

    Rails.application.routes.default_url_options[:protocol]= 'https'
    

    Reference: https://stackoverflow.com/a/6101147/446203

    0 讨论(0)
  • 2020-12-15 06:48

    You need to add the following line:

    proxy_set_header X-Forwarded-Proto https;

    as in

    location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-Forwarded-Proto https;
          proxy_redirect off;
    
          if (!-f $request_filename) {
            proxy_pass http://upstreamy;
            break;
          }
     }
    
    0 讨论(0)
提交回复
热议问题