ElasticSearch HTTP Authentication via Nginx

Source: Internet
Author: User
Tags http authentication nginx server nginx reverse proxy

In the Elasticsearch settings file, if you set the

network.host:0.0.0.0

Indicates that the Elasticsearch service is exposed to any IP that can access the Elasticsearch service. This is certainly not safe.

We can do the login verification for Elasticsearch by installing X-pack, but this is a fee that can only be used for free for 30 days.

Another way is that we often use the Nginx reverse proxy service and use the Http-basic module to do HTTP authentication.

Under nginx Add configuration file content as follows

#upstream dev.es.daojia.com.cn {#//If you have more than one server, you can configure upstream polling here#}server{server_name dev.es.xxx.com.cn; Location/{proxy_http_version1.1; Proxy_set_header Connection"";            Proxy_set_header Host $host; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; Auth_basic"Login"; Auth_basic_user_file/etc/nginx/conf.d/htpasswd;            AutoIndex on; Proxy_pass http://127.0.0.1:9200;} access_log/data/logs/nginx/Dev.es.xxx.com.cn.access.log Main; Error_log/data/logs/nginx/nginx-Error.log;}
Proxy_pass represents the proxy target
Auth_basic_user_file says
Using HTTP://WWW.MATOOLS.COM/HTPASSWD to generate Crypt (all Unix servers) a password in a secret form



You can see that the user named plaintext password is encrypted: delimited

Copy it to the directory file that we set up.

Then modify the configuration of the Elasticsearch network.host

If Nginx and Elasticsearch on the same server can be set to

network.host:127.0.0.1

If you are not on the same machine, set the Network.host option to the IP of the Nginx server.

Then restart Nginx and ElasticSearch

Then we are unable to access the ElasticSearch via IP plus port.

In the Enter the domain name of our configuration to see

Enter your account es123 and password to es123.

ElasticSearch HTTP Authentication via Nginx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.