Revers proxy setup for opensearch-dashboard

Hello Team,

I am using docker container to run the opensearch and opensearch-dashboard.

I wanted to setup revers proxy using vhost in Ubuntu 20.4 server.

I would like to know do we have any documentation related to this?

We just wanted to know the **DocumentRoot" directory path so that we can mentioned it in the vhost configuration for proxy setup.

Thanks.

Hi @sabil -

I think since Nginx is a web server, you’ll still have to provide it a DocumentRoot inside of a server{} directive. Since you have no code to serve up and are only acting as a proxy, I believe the document root can be arbitrary as long as you’re including the proxy_pass directive.

I haven’t done this in a while, but I believe there’s some magic you can perform by using the nginx_http_proxy module as well - you can read all about it at

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

If you find a solution that works for you, I’d love if you came back to share it with everyone! I’d love to see it!

Nate

Hello @nateynate,

Thank you for your suggestion.

The thing is that we are using apache currently in our environment. By any chance do you have any idea about apache configuration for revers proxy for opensearch…

Thank you in advance! :slight_smile:

1 Like

Not sure off the top of my head, but a quick web search reveals the documentation for Apache’s REverse Proxy Guide at Reverse Proxy Guide - Apache HTTP Server Version 2.4

The gist of it is this piece that would go in your httpd.conf under your virutalhost directives.

ProxyPass "/" "http://www.example.com/"
ProxyPassReverse "/" "http://www.example.com/"

This would make Apache redirect any requests starting with / to your backend. The ProxyPassReverse makes it so that the Location headers are re-written to point at the reverse proxy instead of what’s on the backend (in the case of a 302 or 301 redirect).

That should get you started, however I very much suggest referring to the Reverse Proxy guide and experimenting a little bit.

Nate

@nateynate Thank you so much for your help and support…

1 Like

I’m glad I can be of help! If you end up building your solution, bring your config back here for the rest of us to learn from!

Nate

@nateynate Yes sure. So far the solution is not working…

However, I will defiantly post it here for others if the working solution is with me.

Thanks.

Hello @nateynate,

I am able to made some progress on reverse proxy setup for Opensearch dashboard.

The challenge/issue I am facing is when I give port 5601 in proxypass and proxypassrevers the URL is not working at all… When I try to change the port from 5601 to 9200 (opensearch-node) I am getting an output (Opensearch information) on the web browser using proxy URL

Do you have any idea about the DocumentRoot for opensearch-dashbaord? Or is there any setting or configure we can give for a opensearch-dashbaord to get it work.

Thanks.
Sabil.

Welcome back @sabil! Do you mind pasting the appropriate sections of httpd.conf defining your proxypass settings?

This is what we have working with Apache (bearing in mind these are docker containers so Apache is listening on external 80/443, but communicating to the dashboard on the docker network on 5601)

There’s some additional bits on proxying to another non-dashboard URI and some authentication stuff, but left those out for brevity.

<VirtualHost *:80>
    ServerName localhost
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost _default_:443>

# General setup for the virtual host
DocumentRoot "/usr/local/apache2/htdocs"
ServerName localhost
ServerAdmin you@localhost


ProxyPass "/"  "http://opensearch-dashboards:5601/"
ProxyPassReverse  "/" "http://opensearch-dashboards:5601/"
1 Like

A couple of things seem off to me here, but without more specifics about what is going wrong, I’m afraid I’ll have to throw out a few more guesses.

Firstly, you’re redirecting https requests back to http in your proxypass directive. You probably want to replace http with https in your rewrite target. You may also need to add the directive

SSLProxyEngine on

to be included in your configuration. Can you describe a bit more about what’s not working and we’ll go from there?

P.S. There might be some known-to-be-working examples by searching google for working proxypass configuration examples. There might be some eccentricity of the configuration that I’m missing.

Actually, my config works - it’s a bit incomplete - was just showing a small extract since @sabil had asked for a working example.

If their dashboard is running SSL, then they’ll need to configure such - as I noted, we’re using docker containers, so the dashboard instance is not exposed to any external interfaces, only the docker internal network, while Apache is exposed and running TLS.

2 Likes

Thanks @rick98 - I had mistakenly assumed that OP responded and not someone new trying to help. That’s my bad. :slight_smile:

Hello @nateynate and @rick98,

Thank you so much for your suggestion and assistance.

I have a solution which is working fine now. :slight_smile:

My scenario is little different, we have an application which is running on “/” in reverse proxy and I wanted to run additional application which is “opensearch-dashboard” using apache reverse proxy on another path.
In this scenario I wanted to change the entry point/base URL of opensearch-dashboard to “/opnesearch-dashboard” instead of “/”. To achieve this I have added couple of environment variable to docker-compose.yml file as follows.

- "SERVER_BASEPATH=/opensearch-dashboard"
- "SERVER_REWRITEBASEPATH=true"

Following is the configuration of .conf file.

<Location /opensearch-dashboard>
ProxyPass http://127.0.0.1:5601/opensearch-dashboard
ProxyPassReverse http://127.0.0.1:5601/opensearch-dashboard
</Location>

Hope I am able to explain properly. If not feel free to ask question and I am happy to answer here.

Thank you once again
Sabil.

1 Like

Thanks @sabil ! I didn’t know about the SERVER_BASEPATH options!