Elasticsearch & NGINX – Better Together | NGINX

Original: https://www.nginx.com/blog/nginx-elasticsearch-better-together/

Monitoring NGINX Plus Statistics with ELK on our blog.

The Advantages of Deploying NGINX Plus with Elasticsearch

Elasticsearch has a few features designed for scalability, but offloading the load balancing of requests to the open source NGINX product or the commercial NGINX Plus product, which has even more enterprise‑grade features, frees up resources on the Elasticsearch servers.

Putting NGINX or NGINX Plus in front of a single Elasticsearch server provides benefits, such as request logging, but the real value comes when you scale to multiple Elasticsearch servers.

In addition to logging each API request, NGINX and NGINX Plus

The following table compares the functionality available with Elasticsearch by itself, combined with open source NGINX, and combined with NGINX Plus:

Elasticsearch client Open source NGINX NGINX Plus
Horizontal scalability
Keepalive optimization
Centralized HTTP access logs
Queuing and concurrency control
Response caching
Failover of failed connections
Active monitoring of Elasticsearch nodes ✅ (some clients)
Advanced load balancing methods
Weighted load balancing
Dynamic reconfiguration
Status monitoring
General‑purpose HTTP load balancing

When you use NGINX Plus in a high‑availability active/passive configuration to load balance a cluster of Elasticsearch servers, another benefit is that you can configure the Elasticsearch clients to direct requests to NGINX Plus, rather than to the Elasticsearch servers. This means you can scale the Elasticsearch server cluster as needed without having to update the clients.

Deploying NGINX Plus with Elasticsearch

Deploying NGINX Plus with Elasticsearch is very straightforward. The directives in the following sample NGINX Plus configuration define settings for load balancing two Elasticsearch servers:

# in the 'http' context
proxy_cache_path /var/cache/nginx/cache keys_zone=elasticsearch:10m inactive=60m;

upstream elasticsearch_servers {
    zone elasticsearch_servers 64K;
    server 192.168.187.132:9200;
    server 192.168.187.133:9200;
}

match statusok {
    status 200;
    header Content-Type ~ "application/json";
    body ~ '"status" : 200';
}

server {
    listen 9200;
    status_zone elasticsearch;
    location / {
        proxy_pass http://elasticsearch_servers;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache elasticsearch;
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;
        proxy_connect_timeout 5s;
        proxy_read_timeout 10s;
        health_check interval=5s fails=1 passes=1 uri=/ match=statusok;
    }

    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    access_log logs/es_access.log combined;
}

server {
    listen 8080;
    root /usr/share/nginx/html;

    location / {
        index status.html;
    }

    location =/status {
        status;
    }
}

Summary

Elasticsearch, a powerful and flexible search engine, and NGINX Plus, an enterprise‑grade application delivery platform, fit naturally together as components of a modern scalable web architecture. As software products, they provide the same features and functions wherever you install them: on bare‑metal servers, in virtual machines, in the cloud, or in containers.

To try out NGINX Plus with Elasticsearch for yourself, start your free 30‑day trial of NGINX Plus today or contact us for a live demo.

Further Reading

Playing HTTP Tricks with Nginx on the Elasticsearch blog

Securing Elasticsearch with Nginx by James McFadden

Monitoring NGINX Plus Statistics with ELK on our blog

Retrieved by Nick Shadrin from nginx.com website.