我在azure網站上的IIS中部署了node.js服務器,並且我想阻止或重定向http請求。我在我的服務器中使用express + socket.io。在azurewebsites上的node.js服務器中強制HTTPS請求
我發現2種方法來做到這一點:
- 在實際socket.io代碼通過passing allowRequest parameter到socket.io。所以我的代碼看起來像:
var checkRequest = function (req, fn) {
fn(err, true);
};
var ioOptions = {
pingInterval: socketPingInterval,
pingTimeout: socketPingTimeout,
path: "/" + config.API_VERSION + "/socket.io",
allowRequest : checkRequest
};
_socketListener = io.listen(server, ioOptions);
問題是,代碼永遠不會進入checkRequest法,我不知道爲什麼。
- 將規則添加到web.config文件。我檢查了一些論壇,大家說,如果我添加以下代碼:
<rule name="RedirecttoHTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
將我的HPT請求重定向到HTTPS。但它仍然有效,我可以通過HTTP訪問。
can anyonw help with any option?