在azurewebsites

时间:2016-03-11 00:44:14

标签: node.js azure express socket.io azure-web-sites

我在IIS的Azure网站上部署了node.js服务器,我想阻止或重定向http请求。我在服务器中使用express + socket.io。

我找到了两种方法:

  1. passing allowRequest parameter到socket.io的实际socket.io代码中。所以我的代码看起来像这样:
  2. 
    
        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方法,我不知道为什么。

    1. 将规则添加到web.config文件。我检查了几个论坛,每个人都说如果我添加这个代码:
    2. 
      
      <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>
      &#13;
      &#13;
      &#13;

      它会将我的hpt请求重定向到HTTPS。但它仍然有效,我可以通过HTTP访问。

      任何选项都可以帮助吗?

2 个答案:

答案 0 :(得分:2)

使用Kudu Console,在O(m×n)文件夹中创建一个O(m+n)文件,其中包含以下内容:

                              

applicationhost.xdt

删除您添加到web.config中的任何内容。这应该可行。

答案 1 :(得分:1)

这适用于Azure中的Node web应用程序...

https://stpdev.wordpress.com/2015/09/23/force-https-redirection-for-nodejs-apps-hosted-in-azure/

<rewrite>
    <rules>
        <rule name="Force HTTPS" enabled="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>
相关问题