ubuntu 14.04中Elasticsearch 2.3中Nginx权限认证

作者: 杨文波 2017-01-18 09:40:10

前言:本文实现了nginx简单保护elasticsearch,类似的保护也可以采用elasticsearch 官方插件shield。


 


一、准备密码


1.确认htpasswd是否已经安装


which htpasswd


如果返回路径,说明已经安装




如果没安装,可以采用下列方式安装


Ubuntu


apt-get -y install apache2-utils


Centos


yum -y install httpd-tools


2.生成passfile文件


htpasswd -c -d /etc/nginx/conf.d/pass_file  nginxuser


输入上述命令,会让你输入密码,并确认密码。假如我输入的是pass123。则此时我的账户和密码分别为nginxuser、pass123




从图中可以看到pass_file已经生成在/etc/nginx/conf.d/目录下。


 


二、配置Nginx


1.进入 /etc/nginx/conf.d文件夹,创建nginx_http_auth_basic.conf文件


events {


worker_connections  1024;


}


http {


upstream elasticsearch {


server wb-elk:9200;


}


server {


listen 8080;


auth_basic "Protected Elasticsearch";


auth_basic_user_file /etc/nginx/conf.d/pass_file;


location / {


proxy_pass http://elasticsearch;


proxy_redirect off;


}


}


}


server 可以写127.0.0.1:9200 我这写的是机器名


listen 为端口设置


auth_basic_user_file 指定我们上文生成的pass_file


2.先关闭nginx服务


service nginx stop


service naginx status


先确保这个服务处于停止状态


3.重新启动nginx


nginx -p $PWD/nginx/ -c $PWD/nginx_http_auth_basic.conf


确认下是否启动完成


service nginx status


 


三、验证结果








 


本文永久更新地址:http://www.linuxdiyf.com/linux/27906.html

相关资讯