1
我正在將HTTPS添加到node.js
應用程序,同時將HTTP轉發到HTTPS。我使用下面的代碼位:節點應用程序:Http到Https重定向對本地主機不起作用
// Trusting proxy
self.app.enable('trust proxy');
// Http -> Https redirection middleware
self.app.use(function (req, res, next) {
var schema = req.protocol.toLowerCase();
console.log("Redirection check, schema: " + schema);
if (schema === 'https') {
console.log("Next");
next();
} else {
var tmp = 'https://' + req.headers.host + req.url;
console.log("Redirect to: " + tmp);
res.redirect(tmp);
}
});
一切工作正常,當我瀏覽https://localhost:8443/index.html
,頁面打開罰款。
但是,當我嘗試http://localhost:8443/index.html
時,Chrome似乎將網址重定向或重寫爲localhost:8443/index.html
,並且Chrome始終等待本地主機。我的應用程序沒有控制檯消息。我在Windows 7下使用Chrome。
我的代碼有什麼問題?
有道理。我忘記了在Openshift下,你只需要聽一個端口。但是,當然,我需要在筆記本電腦上安裝第二臺服務器。現在嘗試。 – JVerstry 2014-09-02 13:40:47