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