Way for implementing proxy server goint to elastic cluster

Hello
I am suffuring now.

I am implementing Proxy Server going to Elastic Cluster .

Broswer -->
Elastic Proxy Server (Nginx(prot:8081) --> Express(port:7081)) -->
Elastic Cluster(http://10.150.25.119:5601)

When I try to proxy to cluster, many redirect is occured.
so I added "app.get('/*', ElasticProxy)" in Express.

And I try to proxy again. I got 404 not found error in {domain}/api/core/capabilities.
I don't know what happen.
How can I solve many redirections??
Would you please any solution for me??

  • nginx
    location  /  {
            proxy_pass http://localhost:7081;
            proxy_redirect off;
            proxy_buffering off;
            proxy_http_version 1.1;
            proxy_set_header Connection "Keep-Alive";
            proxy_set_header Proxy-Connection "Keep-Alive";
    }
  • Express
function onProxyReq(proxyReq, req, res) {
    console.log('user connect')
    base64EncodedToken = Buffer.from('elastic:elastic123', "utf8").toString('base64')
    console.log("Base64 Encoded base64EncodedToken : ", base64EncodedToken);

    proxyReq.setHeader('Authorization', 'Basic ' + base64EncodedToken);
    console.log('req header: ', JSON.stringify(req.headers, true, 2))
    console.log('req body: ', JSON.stringify(req.body, true, 2))
    proxyReq.setHeader('Connection', 'Keep-Alive')
    proxyReq.setHeader('Proxy-Connection', 'Keep-Alive')
}
function onProxyRes(proxyRes, req, res) {
    console.log('proxyRes header: ', JSON.stringify(proxyRes.headers, true, 2));
}

// proxy middleware options
const options = {
    target: 'http://10.150.25.119:5601',
    changeOrigin: true,
    onProxyReq,
    onProxyRes
};

const ElasticProxy = createProxyMiddleware(options);

app.get('/', ElasticProxy)
app.get('/*', ElasticProxy)

app.listen(port, function() {
    console.log('listening on 7081 port')
})

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.