您如何强制在Azure网站的node.js上使用https? [英] How do you force express on node.js in Azure Websites to use https?

查看:165
本文介绍了您如何强制在Azure网站的node.js上使用https?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Running on Windows Azure Websites, I want to use ssl via the default *.azurewebsites.net certificate. It works without doing anything, but http is also available for every destination, not just https. How do I force a redirect from http to https? Normally I could just do something like:

var https = require('https');

...

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

...

https.createServer(options, app)

但是由于我不了解* .azurewebsites.net证书的任何信息,例如路径,这将不会起作用。

but since I don't know anything about the *.azurewebsites.net certificate, such as its path, that's not going to work.

我要将所有或部分请求重定向到https?

How do I redirect all or some requests to https?

推荐答案

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

In web.config, add the following rule before any other rule that has 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) code>如果您想要* .azurewebsite.net通配符证书。

You can also just use the normal http.createServer(app) for production if you want to the *.azurewebsite.net wildcard certificate.

参考文献:


  1. 如何在IIS7和Azure中重新使用SSL

  2. URL重写模块配置参考

  1. How to require SSL in IIS7 and Azure with Rewrite
  2. URL Rewrite Module Configuration Reference

这篇关于您如何强制在Azure网站的node.js上使用https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆