为什么ActionDispatch :: Request.original_url返回错误的方案?

Mar*_*eck 6 ssl ruby-on-rails nginx unicorn

我有一个Ruby on Rails应用程序,它在模板中有以下内容......

<form action="<%= request.original_url %>" method="post">

当我通过https请求页面时,我最终得到的表单操作与原始请求具有完全相同的URL,但不是https://生成它,而是http://导致混合内容错误.

我错过了什么?在什么情况下会request.original_url返回错误的方案?

我使用Unicorn和nginx运行Ruby on Rails.

Mar*_*eck 8

看起来这可能是解决问题的方法:

http://blog.seancarpenter.net/2013/09/02/rails-ssl-route-generation-with-nginx-and-unicorn/

因为该站点在nginx中运行,所以nginx正在终止SSL,并且Rails不知道是这种情况.

要将此信息传递给Rails,需要设置nginx配置,以便在X-Forwarded-Proto https将请求转发到appserver 时添加标头.

上面文章中的示例配置显示了......

location @app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; # New header for SSL proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn_something_server; }