【问题标题】:HTTPS issues in azure天蓝色的 HTTPS 问题
【发布时间】:2019-01-03 08:45:14
【问题描述】:

我导入了 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');
});

【问题讨论】:

  • 这里的例子,对吧? github.com/socketio/chat-example
  • @JayGong 在 azure 门户中导入了这个 git --> github.com/fern4lvarez/socketiochatrooms
  • 项目在本地能正常运行吗?您是否检查过错误是否由项目本身引起,而不是来自天蓝色?您尝试了哪些操作?
  • @JayGong 是的,本地工作 100%,天蓝色的新手...我搁置 https,我现在正在测试 http,服务器上出现 404 错误。我的项目位于“公共”文件夹和“wwwroot”文件夹中的“应用程序节点”中,我无法连接,它给了我错误 404。如果我分配虚拟路径目录“socket.io”e 目录天蓝色门户中的物理路径“site\wwwroot\socket.io”,返回错误 403。如何在子文件夹中运行站点以及根文件夹中的节点/socket.io?
  • @JayGong 这个例子我的目录结构 --> i.imgur.com/w46czXG.png

标签: node.js azure socket.io


【解决方案1】:

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

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'))

我对此进行了测试。


更新答案:

我还打开了Web Sockets 选项。

【讨论】:

  • 感谢您的帮助!但我还不能运行该应用程序。我有一个 403 错误 -> i.imgur.com/X8H6afz.png - 在 site\wwwroot 我有 web.confapp.js 文件。我的根目录结构和公共 -> i.imgur.com/rf6OaC8.png。最后是我的app.js -> i.imgur.com/4ADqvZl.png
  • 我更改了应用程序配置。但是,现在显示了这个新错误 -> i.imgur.com/2P8Fx5P.png 错误 405 不允许使用 POST 方法。我绝望了=/
  • 是的! websockets已经打开......问题仍然存在.. =/ ....我有一个想法..将整个项目全部放在root文件夹中。但我需要在同一文件夹中为节点和 php 配置 web.config。有没有办法把它合并成一个web.config
  • @FábioZangirolami 抱歉耽搁了,示例中的静态文件是html,你的意思是修改为php?
  • 我的应用程序没有到 php 文件的路径。由于节点不可操作 .phps .. 我只有到目录的路由 .... 我能够通过在 azure 门户上进行此设置来解决我的问题 -> i.imgur.com/KB1YZJL.png
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-21
  • 2018-01-29
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 2019-11-25
相关资源
最近更新 更多