I am trying to redirect http (80)in https (443)to my express application. For this, I use medium dishes. If I go to https://my-example-domain.com, everything will be all right. But if I go to http://my-example-domain.com, it will not redirect and nothing will appear.
I also have some iptables installed on my ubuntu server
sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 8443 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443
function requireHTTPS(req, res, next) {
if (!req.secure) {
return res.redirect('https://' + req.headers.host + req.url);
}
next();
}
app.set('port', process.env.PORT || 8443);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(requireHTTPS);
app.use(express.json());
app.use(express.urlencoded());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.render('index');
})
https.createServer(options, app).listen(8443);
So my question is: do I just need to add another rule iptables? Or do I need to configure something in my application?
, , , , . : http://my-example-domain.com, . 8443, http://my-example-domain.com:8443, .