which htpasswd
若是返回路径,说明已经安装nginx
若是没安装,能够采用下列方式安装apache
apt-get -y install apache2-utils
yum -y install httpd-tools
htpasswd -c -d /etc/nginx/conf.d/pass_file nginxuser
输入上述命令,会让你输入密码,并确认密码。假如我输入的是pass123。则此时个人帐户和密码分别为nginxuser、pass123elasticsearch
从图中能够看到pass_file已经生成在/etc/nginx/conf.d/目录下插件
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 我这写的是机器名code
listen 为端口设置server
auth_basic_user_file 指定咱们上文生成的pass_fileblog
service nginx stop
service naginx status
先确保这个服务处于中止状态get
nginx -p $PWD/nginx/ -c $PWD/nginx_http_auth_basic.conf
确认下是否启动完成io
service nginx status