Elasticsearch behind NGINX on AWS
28 Sep 2014Hosting on Heroku or any other multi-tenant PaaS means you’re sharing IP security with other people. Now your web services require at least basic auth when interacting with services like MySQL and Elasticsearch. We will run Elasticsearch behind nginx, which will enforce a username/pw for basic auth.
To skip the details and get up and going locally, check out this GitHub repo with a Vagrantfile that uses Docker images to run Elasticsearch behind nginx.
If you want a big boy’s deployment for production, check out AWS’s OpsWorks Layer for Elasticsearch
On to the fun:
High-level Overview
- Nginx will be the only public facing ip, and serve as the gateway to all Elasticsearch nodes.
- Nginx will enforce basic auth before proxying all HTTP requests to the ES nodes in a round robin fashion.
- This will be done using an .htpasswd file.
After you’ve spun up Elasticsearch, go through the following steps:
Example Nginx Proxy File
Generate elasticsearch.htpasswd file
Now run nginx with it pointing to ES, and you’re good to go.
Further reading: Wattpad Engineering’s Using Nginx as a proxy for Elasticsearch.