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