我想在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?
在中web.config,在具有的任何其他规则之前添加以下规则stopProcessing="true"。
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通配符证书,也可以只使用普通版进行生产。
http.createServer(app)
参考文献: