Nginx配置认证登录

  本配置实现Nginx认证登录以免重要信息暴露在公网

  日志收集ELK展示工具kibana免费版不支持密码验证,需要设置Nginx反向代理然后关闭kibana默认端口5601使用Nginx端口登录进行用户名及密码认证

  首先设置nginx反向代理kibana

  nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
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;
}

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
        listen       81;
        server_name  localhost;
        auth_basic "User Authentication";
        auth_basic_user_file /opt/nginx/conf/conf.d/kibana.passwd;
        access_log  /data/logs/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;
        }
    }

  upstream.conf

1
2
3
upstream kibana {
    server 127.0.0.1:5601;
}

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

1
htpasswd -c  kibana.passwd admin

  用户名为admin需要连续输入两遍密码

  如果没有htpasswd命令使用以下命令安装

1
yum install httpd-tools

  生成的密码文件用户名是明文,密码为加密格式

  修改配置文件http-www.conf添加认证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server {
        listen       81;
        server_name  localhost;
        auth_basic "User Authentication";
        auth_basic_user_file /opt/nginx/conf/conf.d/kibana.passwd;
        access_log  /data/logs/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;
        }
    }

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

 

posted @   minseo  阅读(11074)  评论(2编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示