I have setup successfully local Elasticsearch and Kibana using docker compose. They both can be accessed via https://localhost:9200 and http://localhost:5601, respectively. Now I need to setup a Nginx on top of that which will receive requests from the outside and then forward the traffic to Elasticsearch or Kibana downstream services based on the port number. For example, if the Nginx receive requests to this url https://<my_public_ip>:9220 it will forward the traffic to https://localhost:9200, if the Nginx receive requests to this url http://<my_public_ip>:5611 it will forward the traffic to http://localhost:5601.
How do I setup/configure this Nginx to do this logic using Dockerfile or Docker compose? Many thanks.
2
Answers
I finally worked it out here and would like to share with anyone who is looking for the same solution.
I installed Elasticsearch and Kibana using Docker compose from this link https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html.
I have created another Nginx docker container using different docker compose file (not merging this into #1 as I can use this for different purposes). Below is the docker compose and nginx.conf file details:
Docker compose:
Note: mycustomnetwork_default must be the same as the one for Elasticsearch and Kibana defined in step #1 so that Nginx container can communicate with.
nginx.conf
You need to set nginx as a proxy
then in your server section, you need to configure the proxy
You may have to work on the hearders to pass via proxy and be careful if elastic/kibana does some redirect because now the redirect may need to take into consideration the nginx
another aspect is that usually, a proxy can downgrade https to http . so your server will need some certificate
Hope it helps to guide you in the right direction