【问题标题】:HTTPS and iisnodeHTTPS 和 iisnode
【发布时间】:2016-02-25 11:07:15
【问题描述】:

我通过iisnode 将node 与IIS 结合使用。

在我看来,以前在 Node 中配置服务器的操作现在可以直接在 IIS 中完成。

类似的东西:

  • https 配置(和证书)
  • http 到 https 重定向

这是否意味着我可以摆脱执行该操作的节点代码而只使用 IIS 方法?

var fs = require('fs');
var https = require('https');

var options = {
    key: fs.readFileSync('./ssl/xxxxxxx.private.pem'),
    cert: fs.readFileSync('./ssl/xxxxxxx.public.pem'),
};

https.createServer(options, app).listen(443);

【问题讨论】:

    标签: node.js iis iis-8.5 iisnode


    【解决方案1】:

    您的密钥和 pfx 不应该存在于文件系统中。一次失误可以将您的文件发送到互联网,现在每个人都可以获得您的密钥。最好将它们存储在 windows cert store 中。

    是的。您应该在 IIS 和 Windows 上进行所有 ssl 配置。

    这是我在生产中使用的。

    在应用程序上,您应该简单地写:

    var app = express();
    app.listen(process.env.port);
    

    那么 iisnode 的 web.config 应该如下所示:

    <configuration>
      <system.webServer>
    
        <handlers>
          <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
        </handlers>
    
    
    <rewrite>
      <rules>
        <rule name="HTTP to Prod HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
        <!-- Don't interfere with requests for logs -->
        <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$" />
        </rule>
        <!-- Don't 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 application entry point -->
        <rule name="DynamicContent">
          <conditions>
             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="app.js" />
        </rule>
      </rules>
    </rewrite>
    
      </system.webServer>
    </configuration>
    

    【讨论】:

    • 正是我需要的!谢谢。
    • 在这里工作!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 2015-09-23
    • 2013-12-08
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    相关资源
    最近更新 更多