Elasticsearch:使用 Nginx 来保护 Elastic Stack
安装
Elastic Stack
Nginx
sudo apt-get install nginx
sudo apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/htpasswd.users kibanauser
$ sudo htpasswd -c /etc/nginx/htpasswd.users kibanauser New password: Re-type new password: Adding password for user kibanauser
sudo vi /etc/nginx/conf.d/kibana.conf
/etc/nginx/conf.d/kibana.conf
upstream elasticsearch { server 127.0.0.1:9200; keepalive 15; } upstream kibana { server 127.0.0.1:5601; keepalive 15; } server { listen 8881; location / { auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/htpasswd.users; proxy_pass http://elasticsearch; proxy_redirect off; proxy_buffering off; proxy_http_version 1.1; proxy_set_header Connection "Keep-Alive"; proxy_set_header Proxy-Connection "Keep-Alive"; } } server { listen 8882; location / { auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/htpasswd.users; proxy_pass http://kibana; proxy_redirect off; proxy_buffering off; proxy_http_version 1.1; proxy_set_header Connection "Keep-Alive"; proxy_set_header Proxy-Connection "Keep-Alive"; } }
sudo service nginx restart
验证身份证
curl --verbose http://127.0.0.1:8881
$ curl --verbose http://127.0.0.1:8881 * Trying 127.0.0.1:8881... * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 8881 (#0) > GET / HTTP/1.1 > Host: 127.0.0.1:8881 > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 401 Unauthorized < Server: nginx/1.18.0 (Ubuntu) < Date: Tue, 05 Jan 2021 02:37:57 GMT < Content-Type: text/html < Content-Length: 188 < Connection: keep-alive < WWW-Authenticate: Basic realm="Restricted Access" < <html> <head><title>401 Authorization Required</title></head> <body> <center><h1>401 Authorization Required</h1></center> <hr><center>nginx/1.18.0 (Ubuntu)</center> </body> </html> * Connection #0 to host 127.0.0.1 left intact
curl --verbose http://kibanauser:1234@127.0.0.1:8881
$ curl --verbose http://kibanauser:1234@127.0.0.1:8881 * Trying 127.0.0.1:8881... * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 8881 (#0) * Server auth using Basic with user 'kibanauser' > GET / HTTP/1.1 > Host: 127.0.0.1:8881 > Authorization: Basic a2liYW5hdXNlcjoxMjM0 > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Server: nginx/1.18.0 (Ubuntu) < Date: Tue, 05 Jan 2021 02:42:25 GMT < Content-Type: application/json; charset=UTF-8 < Content-Length: 531 < Connection: keep-alive < { "name" : "liuxgu", "cluster_name" : "elasticsearch", "cluster_uuid" : "6DeOscunTaevVlsn68DYYA", "version" : { "number" : "7.6.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f", "build_date" : "2020-03-26T06:34:37.794943Z", "build_snapshot" : false, "lucene_version" : "8.4.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } * Connection #0 to host 127.0.0.1 left intact
目录 返回
首页