【问题标题】:Access to nodejs through apache通过apache访问nodejs
【发布时间】:2017-03-01 10:56:11
【问题描述】:

我想在我的 nodejs 应用程序上添加安全性。

为此,我添加了一个带有 apache 的 proxyReverse 来使用 apache 访问我的节点应用程序。 它正在工作,但问题是我仍然能够在不通过 apache 的情况下访问我的节点应用程序...

我的节点站点位于 mydomain:8080/html/site.html 我在 mydomain/site 上使用 apache 访问节点

所以我想要的是将 mydomain:8080/html/site.html 重定向到 mydomain/site ...

但我害怕打无限电话。

这是我的节点server.js

var express = require('express');
var port = 8080;
/*------------------------
        Configuration
 ------------------------*/
app = express();
app.use(express.static('public'));

app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});

/* Port d'ecoute du serveur */
app.listen(port);

这是我的 apache2.conf

<VirtualHost 172.30.0.10:80 >
        ServerName "mydomain:80"
        UseCanonicalName Off


        ProxyPass /site http://mydomain:8080/html/site.html
        ProxyPassReverse /site http://mydomain:8080/html/site.html

        <Proxy *>
                Order deny,allow
                Allow from all
                Authtype Basic
                Authname "Password Required"
                AuthUserFile /etc/apache2/passwords
                Require valid-user
        </Proxy>

</VirtualHost>

我需要你的帮助和建议!提前感谢您阅读本文!

【问题讨论】:

  • 你有任何答案吗???

标签: angularjs node.js apache security reverse-proxy


【解决方案1】:

改变这个:

app.listen(port);

到这里:

app.listen(port, 'localhost');

在您的 Apache 配置中使用 localhost:8080 而不是 mydomain:8080

这将告诉您的 Node 应用程序仅在环回接口上进行侦听,并且它不会回复来自与其自身不同的主机的任何请求。但要使其正常工作,您必须将代理配置更改为 localhost,因为您的代理将无法使用与环回不同的接口连接到 Node 应用,即使它位于同一台计算机上。

处理所有这些的另一种方法是在 TCP/IP 级别过滤数据包,但首先绑定到特定接口更容易。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-19
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多