【问题标题】:ArangoDB Web Interface Behind Node.js Reverse Proxy - Cannot ConnectNode.js 反向代理背后的 ArangoDB Web 界面 - 无法连接
【发布时间】:2019-04-08 06:21:14
【问题描述】:

我有一个 Node.js 后端,用于身份验证和 ArangoDB Web 界面的反向代理。我终其一生都无法弄清楚为什么我无法使用我的外部 URL 登录 Web 界面。

我搜索了高低(google、堆栈溢出、arangodb git 问题线程、arangodb 应用程序代码等),但无法弄清楚。我不喜欢我在下面使用的 node-http-proxy 模块。如果有人以另一种方式在节点内部完成此操作。

我已经看到使用 nginx 等的示例,但我真的试图将所有内容保留在节点后端下,以便能够将代理访问保持在我的站点身份验证之后,因此我不会将 Web 界面暴露给随机访问。

我希望已经清除了这个障碍的人可以提供帮助。

问题: _open/auth 请求从未得到响应。我仍然可以从服务器访问http://localhost:8529 并正常登录。

期望的结果: 从http://example.com:8080/_db/_system/_admin/aardvark/index.html#login访问web界面并成功登录。

[Chrome 标头网络详细信息]:

Request URL: http://example.com:8080/_db/_system/_open/auth
Referrer Policy: no-referrer-when-downgrade

Request Headers:
Provisional headers are shown
Accept: application/json, text/javascript, */*; q=0.01
Authorization: bearer null
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Origin: http://example.com:8080
Referer: http://example.com:8080/_db/_system/_admin/aardvark/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
X-Requested-With: XMLHttpRequest

Form Data:
{"username":"username","password":"password"}: 

有趣的是:http://127.0.0.1:8080/_db/_system/_admin/aardvark/foxxes/fishbowl 总是会出现 401 错误(即使在服务器上的 localhost 地址和端口上,也认为是 aardvark.js 的错误)

请参阅下面的配置文件。

[routes.js]:

// =====================================
// ArangoDB Web interface ============
// =====================================
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({followRedirects: true});

// set headers location overwrite per arangodb documentation
proxy.on('proxyReq', function(proxyReq, req, res, options) { 
    proxyReq.setHeader('X-Script-Name', 'http://example.com:8080');
});

proxy.on('error', function(e) {
    console.log(e);
});

app.all('*/_db/*', function(req, res) {
    proxy.web(req, res, {target: 'http://localhost:8529'});
});

[/etc/arangodb3/arangod.conf]:

[frontend]
proxy-request-check=false
version-check=false
[http]
trusted-origin=all
allow-method-override=true

注意:我也尝试过 'trusted-origin=*'(不确定哪个是正确的)

【问题讨论】:

    标签: node.js arangodb node-http-proxy


    【解决方案1】:

    已解决

    希望这对其他人有所帮助!!!

    我完全错过了您必须手动将表单数据转发到代理的事实(认为它会自动执行此操作)。当您获取帖子正文并将 :"" 附加到值的末尾时,加上 node/arango 做了一些奇怪的事情。所以你必须手动删除它。

    // =====================================
    // ArangoDB query interface Route ========
    // =====================================
    // Add the following to the arangodb config file /etc/arangodb3/arangodb.conf
    // [frontend]
    // proxy-request-check = false
    // [http]
    // trusted-origin = *
    // trusted-origin = all
    
    // Create the proxy
    var httpProxy = require('http-proxy');
    var proxy = httpProxy.createProxyServer();
    
    // Catch requests, massage the login form json, and pass along to the proxied server
    proxy.on('proxyReq', function(proxyReq, req, res, options) {
        var bodyData;
        var contentType = proxyReq.getHeader('Content-Type');
    
        if (!req.body || !Object.keys(req.body).length) {
            return;
        };
        if (contentType == 'application/json; charset=UTF-8' || contentType == 'application/json') {
            bodyData = JSON.stringify(req.body);
        };
    
        if (contentType == 'application/x-www-form-urlencoded; charset=UTF-8' || contentType == 'application/x-www-form-urlencoded') {
            bodyData = queryString.stringify(req.body);
        };
    
        // handle formatting issue with arangodb web form where it appends a :"" to the end of the credentials (i.e. {"username","root","password","password"}:"")
        if (bodyData) {
            if (req.url.substr(-23) == '/_db/_system/_open/auth') {
                proxyReq.write(String(Object.keys(req.body)[0]))
            } else {
                proxyReq.write(bodyData);
                proxyReq.end();
            };
        };
    });
    
      proxy.on('error', function(e) {
          console.log(e);
      });
    
      // note I have two functions to ensure that a user is logged in and has a specific role before they can login to the database. Insert authentication functions / middleware before the function(req, res) below
      app.all('*/_db/*', function(req, res) { //, isLoggedIn, inRole('admin')
          proxy.web(req, res, {target: 'http://127.0.0.1:8529'});
      });
    

    【讨论】:

      猜你喜欢
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 2019-06-08
      • 2019-06-10
      • 1970-01-01
      相关资源
      最近更新 更多