2013-07-10 30 views
0

我想在西納特拉使用這一切HTTPS流量重定向到http如何在heroku上將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?

+0

我可能會嘗試:http://icelab.com.au/articles/useful-heroku-friendly-rewrites-with-rack-rewrite/ – zlog

回答

0

如果您打算使用該代碼,那麼我會使它成爲一個before篩選器,因爲它實際上就是這樣。但是,如果您在應用程序層(這是您的Sinatra應用程序在Heroku上的位置)收到請求,那麼您需要一個證書,因爲HTTP層(處理此問題的Nginx代理服務器位於此處)具有已經收到請求並將嘗試將其作爲安全連接處理,但由於沒有證書而失敗/引發錯誤。如果您嘗試通過https URI方案嘗試訪問非SSL頁面/網站,那麼您會收到此消息。您仍然可以訪問該網站,但用戶必須點擊過去的可怕警告。

我知道可能工作的唯一方法沒有證書(但看着this answer probably not)是,如果你有機會訪問Nginx的配置也做了URL(也可能是一些頭)出現的重寫。

相關問題