【问题标题】:Configuring SSL endpoints for node.js worker roles on Azure在 Azure 上为 node.js 辅助角色配置 SSL 端点
【发布时间】:2013-06-15 18:17:59
【问题描述】:

我已经设置了一个 node.js 应用程序以在 Azure 云服务上的辅助角色(而不是 Web 角色)上运行。在 HTTP 上运行的标准应用程序一切正常。

现在我正在尝试让它在 HTTPS 上通过 SSL 运行,并已成功按照http://www.windowsazure.com/en-us/develop/nodejs/common-tasks/enable-ssl-worker-role/ 的说明进行操作,但它没有产生正确的结果!

现在,当通过 HTTP 或 HTTPS 访问 url 时,连接超时并且没有返回任何内容。

是否有任何我可能遗漏的内容或上面链接的指南中未包含的任何步骤?

我在指南中注意到的一件事是这条线是否......

<InputEndpoint name="HttpIn" protocol="tcp" port="443" />

...实际上应该是 HttpsIn 吗?虽然改变这一点似乎并没有太大的不同。


更新:这是我的一些配置文件

ServiceConfiguration.cloud.cscfg

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serviceName="*removed*" osFamily="2" osVersion="*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
  <Role name="WorkerRole1">
    <ConfigurationSettings />
    <Instances count="1" />
    <Certificates>
      <Certificate name="certificateName" thumbprint="*removed*" thumbprintAlgorithm="sha1" />
    </Certificates>
  </Role>
</ServiceConfiguration>

ServiceDefinition.csdef

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="*removed*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WorkerRole name="WorkerRole1" vmsize="ExtraSmall">
    <Startup>
      <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated">
        <Environment>
          <Variable name="EMULATED">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
          <Variable name="RUNTIMEID" value="node" />
          <Variable name="RUNTIMEURL" value="http://az413943.vo.msecnd.net/node/0.8.4.exe" />
        </Environment>
      </Task>
      <Task commandLine="node.cmd .\startup.js" executionContext="elevated" />
    </Startup>
    <Endpoints>
      <InputEndpoint name="HttpIn" protocol="http" port="80" />
      <InputEndpoint name="HttpsIn" protocol="https" port="443" certificate="certificateName" />
    </Endpoints>
    <Certificates>
      <Certificate name="certificateName" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
    <Runtime>
      <Environment>
        <Variable name="PORT">
          <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" />
        </Variable>
        <Variable name="EMULATED">
          <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
        </Variable>
      </Environment>
      <EntryPoint>
        <ProgramEntryPoint commandLine="node.cmd .\server.js" setReadyOnProcessStart="true" />
      </EntryPoint>
    </Runtime>
  </WorkerRole>
</ServiceDefinition>

我还尝试了这些的各种变体(使用更少的额外标签和属性),但似乎没有任何效果。

【问题讨论】:

  • name 属性只是一个名称。 protocolport 属性是重要的属性,它们根据您引用的配置和文档正确设置。为了帮助您,您需要在您的问题中粘贴您的节点云服务的.csdef.cscfg 文件。您可能更改了其他内容。您引用的说明是正确和准确的。
  • 感谢您对名称的澄清。我已经用一些配置文件更新了我的帖子。最初我没有更改任何其他内容,但由于它不起作用,我尝试添加一些额外的位(似乎没有任何帮助),直到您在上面看到粘贴的内容。

标签: node.js azure https azure-worker-roles


【解决方案1】:

您提供的protocol 值为HttpInHttpsIn。您应该将这些值用于 ASP.NET Web 角色!当您在 Worker Roles 上运行第 3 方 Web 服务器时,您应该使用 tcp 作为 protocol 属性的值!!改变这是使事情不起作用的最简单方法!您能否将它们切换回 tcp,从 Https Endpoint 中删除 certificate 属性并重试?

此外,默认示例应用程序 server.js 仅侦听一个端口。这是由为启动任务定义的环境值PORT 传递的。如果您需要 HTTPS 流量,您应该在此处引用 HttpsIn 端点。不幸的是,我不知道 node.js 是否可以通过这个简单的设置同时处理 http 和 https 流量。

更新

请使用以下.csconfig文件(将您在文件夹中看到的所有.csconfig文件的内容替换为我提供的内容):

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="*removed*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WorkerRole name="WorkerRole1" vmsize="ExtraSmall">
    <Startup>
      <Task commandLine="setup_worker.cmd &gt; log.txt" executionContext="elevated">
        <Environment>
          <Variable name="EMULATED">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
          <Variable name="RUNTIMEID" value="node" />
          <Variable name="RUNTIMEURL" value="http://az413943.vo.msecnd.net/node/0.8.4.exe" />
        </Environment>
      </Task>
      <Task commandLine="node.cmd .\startup.js" executionContext="elevated" />
    </Startup>
    <Endpoints>
      <InputEndpoint name="HttpsIn" protocol="https" port="443" />
    </Endpoints>
    <Certificates>
      <Certificate name="certificateName" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
    <Runtime>
      <Environment>
        <Variable name="PORT">
          <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpsIn']/@port" />
        </Variable>
        <Variable name="EMULATED">
          <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
        </Variable>
      </Environment>
      <EntryPoint>
        <ProgramEntryPoint commandLine="node.cmd .\server.js" setReadyOnProcessStart="true" />
      </EntryPoint>
    </Runtime>
  </WorkerRole>
</ServiceDefinition>

另外,请在您的server.js 文件中提供代码 - 至少在完成绑定的前 10 行。并且在更改之后,请执行以下命令行并告诉我们结果是什么:

c:>telnet [your_cloud_service].cloudapp.net 443

另外请确认您在执行 powershell 命令的文件夹中有 .pfx 文件。

【讨论】:

  • 好的,我的端点部分现在又是&lt;InputEndpoint name="HttpsIn" protocol="tcp" port="443" /&gt;,但不幸的是我遇到了同样的问题,即尝试通过 https 或 http 访问时连接超时。还有其他建议吗?
  • 谢谢!现在一切似乎都在工作。我不确定到底是什么修复了它。我在 WorkerRole1 文件夹中有 .pfx 文件,因此也将其复制到父文件夹中,并按照您上面的建议更改了该行上的 name 属性&lt;RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpsIn']/@port" /&gt;
猜你喜欢
  • 2015-04-12
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
  • 2014-11-09
  • 1970-01-01
相关资源
最近更新 更多