【问题标题】:How do I redirect all https traffic to http in Sinatra on heroku?如何在 Heroku 上将所有 https 流量重定向到 Sinatra 中的 http?
【发布时间】:2013-07-08 01:57:52
【问题描述】:

我正在尝试在 Sinatra 中使用此将所有 https 流量重定向到 http

  get "*" do
      if request.secure?
        redirect request.url.gsub(/^https/, "http")
      else
        pass # continue execution
      end   
    end

但是,在 heroku 上的自定义域上,我的浏览器显示错误:

This is probably not the site you are looking for!

You attempted to reach www.[domain].com, but instead you actually reached a server identifying itself as *.heroku.com. 

我的 DNS 配置了 www 子域,其 CNAME 指向 [domain].herokuapp.com,根据 https://devcenter.heroku.com/articles/custom-domains

这是 DNS 问题吗?购买 SSL 证书是允许所有 https 流量在 heroku 上重定向到 http 的唯一方法吗?

【问题讨论】:

标签: heroku dns sinatra


【解决方案1】:

如果您要使用该代码,那么我会将其设为 before 过滤器,因为它确实是这样的。

但是,如果您在应用程序层(即您的 Sinatra 应用程序在 Heroku 上的位置)收到请求,那么您需要一个证书,因为 HTTP 层(处理此位置的 Nginx 代理服务器)已经收到请求并将尝试将其作为安全连接处理,但由于没有证书而失败/引发错误。如果您尝试通过https URI 方案访问非 SSL 页面/站点,您将收到该消息。您仍然可以访问该网站,但用户必须点击一个可怕的警告。

我知道可能在没有证书的情况下工作的唯一方法(但查看this answer probably not)是如果您有权访问 Nginx 配置并重写了 URL(可能还有一些标题)那里。

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 2012-04-19
    • 2014-04-27
    • 2016-07-27
    • 2019-09-06
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    相关资源
    最近更新 更多