# RestHighLevelClient - Accessing an elastic http endpoint behind reverse proxy

**URL:** <https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306>\
**Category:** Elasticsearch\
**Created:** [January 27, 2018, 2:30pm UTC](https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306 "2018-01-27T14:30:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![missourian](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@missourian](https://discuss.elastic.co/u/missourian)\
**Post date:** [January 27, 2018, 2:30pm UTC](https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306/1 "2018-01-27T14:30:42Z")

</div>

My elasticsearch http endpoint has been fronted with a corporate reverse proxy and also it has a **path prefix**. I am in the process of migrating from Transport client to HighLevelHttpClient can someone help me how to configure the elastic http endpoint behind an reverse proxy?

**here elastic is the reverse proxy path prefix**  
\> $ curl -v [http://localhost:9090/elastic](http://localhost:9090/elastic)

> ```
> * STATE: INIT => CONNECT handle 0x6000579e0; line 1423 (connection #-5000)
> * Added connection 0. The cache now contains 1 members
> * STATE: CONNECT => WAITRESOLVE handle 0x6000579e0; line 1459 (connection #0)
> * Trying ::1...
> * TCP_NODELAY set
> * STATE: WAITRESOLVE => WAITCONNECT handle 0x6000579e0; line 1540 (connection #0)
> * Connected to localhost (::1) port 9090 (#0)
> * STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000579e0; line 1592 (connection #0)
> * Marked for [keep alive]: HTTP default
> * STATE: SENDPROTOCONNECT => DO handle 0x6000579e0; line 1610 (connection #0)
> > GET /elastic HTTP/1.1
> > Host: localhost:9090
> > User-Agent: curl/7.56.1
> > Accept: */*
> >
> * STATE: DO => DO_DONE handle 0x6000579e0; line 1689 (connection #0)
> * STATE: DO_DONE => WAITPERFORM handle 0x6000579e0; line 1814 (connection #0)
> * STATE: WAITPERFORM => PERFORM handle 0x6000579e0; line 1824 (connection #0)
> * HTTP 1.1 or later with persistent connection, pipelining supported
> < HTTP/1.1 200 OK
> < Connection: keep-alive
> < Transfer-Encoding: chunked
> < Content-Type: application/json;charset=UTF-8
> < X-Application-Context: company-proxy:9090
> < Date: Sat, 27 Jan 2018 14:23:23 GMT
> <
> {
> "name" : "node-1",
> "cluster_name" : "my-application",
> "cluster_uuid" : "1K3Am20jSQ2KtALLgXvIXA",
> "version" : {
> "number" : "6.1.2",
> "build_hash" : "5b1fea5",
> "build_date" : "2018-01-10T02:35:59.208Z",
> "build_snapshot" : false,
> "lucene_version" : "7.1.0",
> "minimum_wire_compatibility_version" : "5.6.0",
> "minimum_index_compatibility_version" : "5.0.0"
> },
> "tagline" : "You Know, for Search"
> }
> * STATE: PERFORM => DONE handle 0x6000579e0; line 1993 (connection #0)
> * multi_done
> * Connection #0 to host localhost left intact
> * Expire cleared
> 
> ```

**JAVA Config** how to pass the URL ([http://localhost:9090/elastic](http://localhost:9090/elastic) instead of host and port)

> ```
> @Bean
> public RestHighLevelClient elasticClient() {
> 
> return new RestHighLevelClient(RestClient.builder(
> new HttpHost(elastichost, elasticport, DEFAULT_SCHEME_NAME)));
> 
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![missourian](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@missourian](https://discuss.elastic.co/u/missourian)\
**Post date:** [January 30, 2018, 12:59am UTC](https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306/2 "2018-01-30T00:59:16Z")

</div>

Well, I did find the answer. I should have investigated the API little more 🙂

@Bean  
public RestHighLevelClient elasticClient() {

```
return new RestHighLevelClient(RestClient.builder(
    new HttpHost(elastichost, elasticport, DEFAULT_SCHEME_NAME)).setPathPrefix("/elastic"));

```

}

Tookcare of the reverse proxy path prefix

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2018, 4:46am UTC](https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306/3 "2018-01-30T04:46:31Z")

</div>

Ha great! I was not aware either of this method.

Thanks for sharing your solution! 😉

---

<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:** [February 27, 2018, 4:46am UTC](https://discuss.elastic.co/t/resthighlevelclient-accessing-an-elastic-http-endpoint-behind-reverse-proxy/117306/4 "2018-02-27T04:46:43Z")

</div>

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