Cur*_*ous 3 ssl https node.js express azure-web-sites
在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)
Run Code Online (Sandbox Code Playgroud)
但是因为我对*.azurewebsites.net证书一无所知,比如它的路径,所以不行.
如何将所有或部分请求重定向到https?
在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>
Run Code Online (Sandbox Code Playgroud)
http.createServer(app)如果您想要*.azurewebsite.net通配符证书,也可以使用正常生产.
参考文献:
小智 5
接受的答案对我不起作用,它只显示一个空白页面,这个:
<!-- Redirect all traffic to SSL -->
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
从https://gist.github.com/tstpierre/afec7eb409aebe0bf3d1可以很好地工作.
| 归档时间: |
|
| 查看次数: |
3495 次 |
| 最近记录: |