将 nginx 作为反向代理服务器,并增加登录用户认证的目的,可以有效避免其 他人员随意访问 kibana 页面。
安装nginx
tar xf nginx-1.10.3.tar.gz
./configure --prefix=/usr/local/nginx
make && make install
准备 systemctl 启动文件
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
配置并启动 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 文件路径与启动脚本必须一致
配置 nginx 代理 kibana:
实现登录认证
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