# Way for implementing proxy server goint to elastic cluster

**URL:** <https://discuss.elastic.co/t/way-for-implementing-proxy-server-goint-to-elastic-cluster/328889>\
**Category:** Kibana\
**Created:** [March 30, 2023, 6:46am UTC](https://discuss.elastic.co/t/way-for-implementing-proxy-server-goint-to-elastic-cluster/328889 "2023-03-30T06:46:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minkiyo](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@minkiyo](https://discuss.elastic.co/u/minkiyo)\
**Post date:** [March 30, 2023, 6:46am UTC](https://discuss.elastic.co/t/way-for-implementing-proxy-server-goint-to-elastic-cluster/328889/1 "2023-03-30T06:46:09Z")

</div>

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](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??

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/0/c096554927ca75c98a4db998761246325582da58.png)

- nginx

```auto
    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

```auto
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')
})

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 27, 2023, 6:46am UTC](https://discuss.elastic.co/t/way-for-implementing-proxy-server-goint-to-elastic-cluster/328889/2 "2023-04-27T06:46:46Z")

</div>

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