天蓝色的HTTPS问题

时间:2019-01-01 19:51:09

标签: node.js azure socket.io

我导入了git socket.io聊天室项目!该代码在http = require ('http')上正常工作,但是在交换为https = require ('https')时,我的服务器响应错误500 http

var express = require('express')
  , app = express()
 // , http = require('http')
  , https = require('https')
  , fs = require('fs')

  , privateKey  = fs.readFileSync('HTTPS_Permissions/key.key', 'utf8')
  , certificate = fs.readFileSync('HTTPS_Permissions/cert.cert', 'utf8')
  , credentials = {key: privateKey, cert: certificate}
  , httpsServer = https.createServer(credentials, app)

 // , httpServer = http.createServer(app)
  , io = require('socket.io').listen(httpsServer)

  //, port = process.env.PORT || 8080
  , port = process.env.PORT


  httpsServer.listen(port, function () {
    console.log('Server listening on port %d', port);
  });

//httpServer.listen(port);

// routing
app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

1 个答案:

答案 0 :(得分:1)

我关注了您在评论中分享的project,它对我有效。

enter image description here

web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^app.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="app.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <iisnode watchedFiles="web.config;*.js"/>
  </system.webServer>
</configuration>

如果您将index.html直接放入自己在wwwroot/下创建的公用文件夹中,则需要根据以下article将以下代码添加到您的代码中。

app.use(express.static('public'))

enter image description here

我为此做了测试。

enter image description here


更新答案:

我还打开了Web Sockets选项。

enter image description here