How to access elasticsearch as localhost from Nginx server as reverse proxy

How to access as localhost from Nginx server as reverse proxy
I have 4 elasticsearch node on 4 separate servers:

Nginx is running on separate server:

In elasticsearch.yml on each of the above elasticsearch nodes
http.port: 9200

I want to access elasticsearch through NGINX as reverse proxy server as

Going by the Elasticsearch Ip restriction using NGINX
I tried with iptables to restrict elasticsearch access through only NGINX as below on each of the easticsearch nodes

iptables -A INPUT -p tcp --dport 9200 -s -j ACCEPT
iptables -A INPUT -p tcp --dport 9200 -j DROP

It is not working. I am unable access elasticsearch as from nginx server

Can nobody please help me here.

if you bind to localhost/, nginx will not be able to reach elasticsearch over the network.

My idea of having Nginx in front of elastisearch is to protect elasticsearch. I want to restrict direct access of elasticsearch from data/and master nodes without any authorization.
In Nginx config file I am applying Authentication for Elasticsearch.

upstream elasticsearch {
keepalive 15;
server {
listen 8050;
auth_basic "Protected Elasticsearch";
auth_basic_user_file /u11/nginx/config/conf.d/elasticsearch.htpasswd;

  location / {
  proxy_pass http://elasticsearch;
  proxy_set_header Connection "Keep-Alive";
  proxy_set_header Proxy-Connection "Keep-Alive";
  proxy_redirect off;


What action is to be taken in network to proxy_pass from nginx to remote elastic server where in the remote server elasticsearch runs as localhost

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