[Nginx]子目錄反向代理kibana並添加basic認證

背景html

 服務器ip:192.168.1.2nginx

  安裝軟件 nginx kibana(默認端口5601)vim

實現方案:訪問http://192.168.1.2/kibana 便可訪問到kibana後端,同時須要添加basic認證segmentfault

1.準備密碼文件後端

#yum install -y httpd-tools
#htpasswd -c /opt/soft/nginx/conf/kibanauser admin 執行後會提示輸入密碼,admin爲用戶名,最後生成kibanauser文件

 

2.修改nginx配置文件服務器

#vim /opt/soft/nginx/conf/nginx.conf

location /kibana/ {
        auth_basic "secret";
     auth_basic_user_file /opt/soft/nginx/conf/kibanauser;
        proxy_pass http://127.0.0.1:5601/;
        proxy_set_header Host $host:5601;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        rewrite ^/kibana/(.*)$ /$1 break;
}
#重啓nginx

3.修改kibana配置文件spa

vim /etc/kibana/kibana.yml
修改參數以下
server.basePath: "/kibana"
server.host: "127.0.0.1" #修改這一步是爲了禁止外部用戶直接訪問kibana頁面,若是不修改這個參數的話也能夠使用iptables限制外部用戶直接訪問本機的5601端口
重啓kibana systemctl restart kibana

 

完成後便可達到試驗目標rest

參考連接code

https://segmentfault.com/q/1010000011782771server

https://www.cnblogs.com/keithtt/p/6593866.html

相關文章
相關標籤/搜索