# Using NGINX as a Load Balancer

**URL:** <https://discuss.elastic.co/t/using-nginx-as-a-load-balancer/340773>\
**Category:** Elasticsearch\
**Created:** [August 14, 2023, 4:33pm UTC](https://discuss.elastic.co/t/using-nginx-as-a-load-balancer/340773 "2023-08-14T16:33:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [August 14, 2023, 4:33pm UTC](https://discuss.elastic.co/t/using-nginx-as-a-load-balancer/340773/1 "2023-08-14T16:33:03Z")

</div>

I created an Elasticsearch Cluster with 3 Elasticsearch nodes. All nodes are of type master.

They are configured to maintain high availability, one node receives data and replicates it to the other two.

For load balancing I use NGINX, with the configuration below:

```auto
## Custom certificate
ssl_certificate /etc/ssl/myapp/nginx-elk.crt;
ssl_certificate_key /etc/ssl/myapp/nginx-elk.key;

upstream elk {
    server 192.168.0.33:9200;
    server 192.168.0.34:9200;
    server 192.168.0.35:9200;
}

server {
    listen 443 ssl;
    server_name 192.165.1.1; //Public Internet IP
    add_header X-Frame-Options "SAMEORIGIN";
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";

    location / {

        proxy_pass https://elk;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    access_log /var/log/nginx/elk.myapp.com-access.log proxylog;
   }

```

My NGINX server has this Keep Alive setting in nginx.conf

```auto
events {
        worker_connections 50000;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        client_max_body_size 100M;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

```

Do I have to do some other configuration to guarantee performance on access?

I use the VMs local IP to query the ELK and not the public IP. I only use the public IP via the internet in some cases.

---

<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:** [September 11, 2023, 4:33pm UTC](https://discuss.elastic.co/t/using-nginx-as-a-load-balancer/340773/2 "2023-09-11T16:33:46Z")

</div>

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