首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTPS和iisnode

HTTPS和iisnode
EN

Stack Overflow用户
提问于 2015-11-23 11:00:21
回答 1查看 4.2K关注 0票数 11

我使用iisnode结合使用节点和IIS。

在我看来,我以前在Node中为配置服务器所做的事情现在可以直接在IIS中完成。

比如:

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

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

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2017-05-24 17:22:56

您的密钥和pfx不应该存在于文件系统中。一次失误就可以把你的文件送到网上,现在每个人都能拿到你的钥匙。最好将它们存储在windows证书商店中。

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

这就是我在生产上所用的。

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

代码语言:javascript
复制
var app = express();
app.listen(process.env.port);

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

代码语言:javascript
复制
<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>
票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33869417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档