小编典典

如何在Azure网站中的node.js上强制Express使用https?

node.js

我想在Windows Azure网站上运行,我想通过默认的*
.azurewebsites.net证书使用ssl。它无需执行任何操作即可工作,但是http也可用于每个目的地,而不仅仅是https。如何强制从http重定向到https?通常我可以做类似的事情:

var https = require('https');

...

var options = {
      key: fs.readFileSync('path.key'),
      cert: fs.readFileSync('path.crt')
    };

...

https.createServer(options, app)

但由于我对* .azurewebsites.net证书一无所知,例如其路径,因此无法正常工作。

如何将全部或部分请求重定向到https?


阅读 157

收藏
2020-07-07

共1个答案

小编典典

在中web.config,在具有的任何其他规则之前添加以下规则stopProcessing="true"

<rule name="RedirecttoHTTPS">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    <add input="{URL}" pattern="/$" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>

http.createServer(app)如果您想获得* .azurewebsite.net通配符证书,也可以只使用普通版进行生产。

参考文献:

  1. 如何通过重写在IIS7和Azure中要求SSL
  2. URL重写模块配置参考
2020-07-07