gpt4 book ai didi

node.js - HTTPS 和 iisnode

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:38 25 4
gpt4 key购买 nike

我通过使用 iisnode 将 Node 与 IIS 结合使用.

我觉得以前在 Node 中配置服务器的事情现在可以直接在 IIS 中完成。

比如:

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

这是否意味着我可以摆脱执行该操作的 Node 代码而只使用 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);

最佳答案

您的 key 和 pfx 永远不应存在于文件系统中。一个失误可能会将您的文件提供给互联网,现在每个人都可以获得您的 key 。最好将它们存储在 Windows 证书商店中。

是的。您应该在 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>

关于node.js - HTTPS 和 iisnode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33869417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com