我有一个有趣的小问题 - Heroku 上的一个应用程序被配置为使用Heroku SSL(测试版)但无论我做什么,它似乎都想使用 HTTPS。
浏览器错误:
I have redirect_to :protocol => 'http://', :status => :moved_permanently
在一个控制器上。对此控制器的请求得到:
www.mysite.com redirected you too many times.
ERR_TOO_MANY_REDIRECTS
相关代码:
DNS设置:
ftp: www.mysite.com.herokudns.com
www: www.mysite.com.herokudns.com
Gemfile:
gem 'rack-ssl-enforcer'
gem 'rack-cors'
生产.rb:
** Not in effect**
#config.force_ssl = true
应用程序.rb:
# Note: no code inserted for rack-ssl-enforcer
config.middleware.insert_before 0, 'Rack::Cors' do
allow do
origins '*'
resource '*', headers: :any, methods: [:get]
end
end
我尝试在一个控制器上避免使用 HTTPS:
requests_controller.rb:
before_action :avoid_ssl
def avoid_ssl
if request.ssl? && Rails.env.production?
redirect_to :protocol => 'http://', :status => :moved_permanently
end
end
我最近添加的代码requests_controller.rb
已引发此错误。我的应用程序中的某些内容希望所有内容都是 HTTPS,但 Heroku 支持告诉我:
“Heroku SSL 没有什么特别之处,必须在应用程序内部执行重定向 - 要跳过给定控制器的‘强制 SSL’,这是一个代码更改”。
是什么可能导致所有内容都重定向到 HTTPS?非常感谢。