將 nginx 作為反向代理服務(wù)器,并增加登錄用戶認(rèn)證的目的,可以有效避免其 他人員隨意訪問(wèn) kibana 頁(yè)面。
安裝nginx
tar xf nginx-1.10.3.tar.gz
./configure --prefix=/usr/local/nginx
make && make install
準(zhǔn)備 systemctl 啟動(dòng)文件
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid #和 nginx 配置文件的保持一致
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置并啟動(dòng) nginx
ln -sv /usr/local/nginx/sbin/nginx /usr/sbin/
useradd www -u 2000
chown www.www /usr/local/nginx/ -R
vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 1;
pid /run/nginx.pid; #更改 pid 文件路徑與啟動(dòng)腳本必須一致
配置 nginx 代理 kibana:
實(shí)現(xiàn)登錄認(rèn)證
yum install httpd-tools –y
htpasswd -bc /usr/local/nginx/conf/htpasswd.users test123456
cat /usr/local/nginx/conf/htpasswd.users
vim /usr/local/nginx/conf/conf.d/kibana1512.conf
upstream kibana_server {
server 127.0.0.1:5601 weight=1 max_fails=3 fail_timeout=60;
}
server {
listen 80;
server_name www.kibana1512.com;
auth_basic "Restricted Access";
auth_basic_user_file /usr/local/nginx/conf/htpasswd.users;
location / {
proxy_pass http://kibana_server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
重啟 nginx
chown www.www /usr/local/nginx/ -R
systemctl restart nginx