Nginx配置认证登录


本配置实现Nginx认证登录以免重要信息暴露在公网
日志收集ELK展示工具kibana免费版不支持密码验证,需要设置Nginx反向代理然后关闭kibana默认端口5601使用Nginx端口登录进行用户名及密码认证

1、安装Nginx

yum install nginx -y

2、首先设置nginx反向代理kibana

编辑nginx.conf配置文件

worker_processes 1;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    log_format access_log_json '{"user_ip":"$http_x_forwarded_for","lan_ip":"$remote_addr","log_time":"$time_iso8601","user_rqp":"$request","http_code":"$status","body_bytes_sent":"$body_bytes_sent","req_time":"$request_time","user_ua":"$http_user_agent"}';
    sendfile on;
    keepalive_timeout 65;
    include conf.d/*.conf;
}

3、在文件夹conf.d下面新建两个配置文件http-www.conf、upstream.conf

# cat http-www.conf
server {
    listen 81;
    server_name localhost;
    auth_basic "User Authentication";
    auth_basic_user_file /etc/nginx/conf.d/kibana.passwd;
    access_log /var/log/nginx/http-access.log access_log_json;
location / {
    proxy_set_header Host $host;
    proxy_set_header x-for $remote_addr;
    proxy_set_header x-server $host;
    proxy_set_header x-agent $http_user_agent;
    proxy_pass http://kibana;
    }
}

# cat upstream.conf
upstream kibana {
   server 192.168.56.12:5601;
} 

4、使用密码工具生产密码文件

htpasswd -c kibana.passwd admin
用户名为admin需要连续输入两遍密码

如果没有htpasswd命令使用以下命令安装
yum install httpd-tools
生成的密码文件用户名是明文,密码为加密格式

5、在web界面登录需要输入用户名和密码


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM