【发布时间】:2017-10-31 05:58:24
【问题描述】:
我正在运行带有 express 模块的服务器 nodeJs。网站是由 React.js 制作的,它是服务器端的。
我有域:www.example.com,Route53 和负载均衡器应用了 AWS 证书管理器。
问题是我不知道如何自动访问 https:// 协议,当我输入 url http://www.example.com
现在,我可以访问每个网址,例如 http://www.example.com 或 https://www.example.com
我找到了解决方案:
app.use (function (enter code herereq, res, next) {
if (req.secure) {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});
但它不起作用......
有什么好方法???
更新
如果使用 nodejs 和 express,如何设置端口? express 块端口 80,所以我使用
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000。连接端口是常用的方法吗?我有使用 SSL (ACM) 的负载平衡器,使用端口的端口是 80、443。 如何直接访问'http'或'https应该访问https。
【问题讨论】:
标签: javascript node.js reactjs amazon-web-services https