我在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?