Node.js HTTPS和iisnode
我正在通过使用将node与IIS结合使用 在我看来,我以前在Node中配置服务器的操作现在可以直接在IIS中完成 例如:Node.js HTTPS和iisnode,node.js,iis,iis-8.5,iisnode,Node.js,Iis,Iis 8.5,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'),
- https配置(和证书)
- http到https重定向
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);
您的密钥和pfx不应存在于文件系统中。一个失误就可以把你的文件传到网上,现在每个人都可以拿到你的钥匙。最好将它们存储在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>
正是我所需要的!谢谢