【问题标题】:How to get req.hostname when running node.js behind apache with mod_proxy使用 mod_proxy 在 apache 后面运行 node.js 时如何获取 req.hostname
【发布时间】:2017-03-27 06:23:36
【问题描述】:

我的 node.js 应用程序使用 req.hostname 来将一些页面从 HTTP 重定向到 HTTPS,如下所示:

app.get('*', function(req, res){
    res.redirect('https://' + req.hostname + req.url);
});

这在本地主机上运行应用程序时效果很好。但是当应用程序在 mod_proxy 后面的服务器上运行时,req.hostname 不包含域名。相反,它只包含localhost。如何获取域名?

【问题讨论】:

    标签: node.js express mod-proxy


    【解决方案1】:

    在您的 apache 设置中,您必须添加以下内容:

    ProxyPreserveHost On
    

    这将告诉 apache 在代理传递到您的节点应用程序时保留主机名

    【讨论】:

      猜你喜欢
      • 2017-03-27
      • 1970-01-01
      • 2017-01-10
      • 2014-06-27
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-26
      • 2014-07-16
      相关资源
      最近更新 更多