Put Elasticsearch behind Nginx reverse proxy

Put Elasticsearch behind Nginx reverse proxy

c.f. https://blog.eagerelk.com/securing-elasticsearch-using-nginx-as-a-proxy/

Nginx with BASIC auth

Install nginx, apach2-utils

sudo apt install nginx apache2-utils

Add new BASIC authentication file

sudo htpasswd -c /etc/nginx/conf.d/search.htpasswd myelasticsearchuser
New password: ********
...

Nginx conf

Nginx config ( /etc/nginx/sites-available/elasticsearch.conf ):

# c.f. https://blog.eagerelk.com/securing-elasticsearch-using-nginx-as-a-proxy/
server {
  listen *:80;
  # Make sure you have domain to use SSL later.
  # If not, use IP address, and without SSL.
  server_name elasticsearch.mydomain;

  access_log /var/log/nginx/elasticsearch.access.log;

  location / {
    auth_basic "Authentication";
    auth_basic_user_file /etc/nginx/conf.d/search.htpasswd;

    proxy_pass http://127.0.0.1:9200;
    proxy_read_timeout 90;

  }
}

SSL using Let’s Encrypt

Install certbot:

https://certbot.eff.org/

Then run certbot:

sudo certbot