【发布时间】:2016-03-11 17:47:59
【问题描述】:
我在 Azure 网站的 IIS 中部署了 node.js 服务器,我想阻止或重定向 http 请求。我在我的服务器中使用 express + socket.io。
我找到了两种方法:
- 在实际的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 访问。
anyonw 可以提供任何选项吗?
【问题讨论】:
标签: node.js azure express socket.io azure-web-app-service