My node.js application uses req.hostname
in order to redirect some pages from HTTP to HTTPS like this:
app.get('*', function(req, res){
res.redirect('https://' + req.hostname + req.url);
});
This works very well when running the application on localhost. But when the application runs on a server behind mod_proxy then req.hostname
does not contain the domain name. Instead it contains just localhost
. How do I get the domain name?
on your apache settings you have to add this:
ProxyPreserveHost On
this will tell the apache to preserve a hostname when doing proxy pass to your node application