配置nginx本地认证样式
server {
    listen       80;
    server_name  www.baidu.com;
    
    auth_basic "User Authentication";
    auth_basic_user_file /etc/nginx/.passwd-www;    
    location / {
        root   /usr/share/nginx/html;
        index  index.html;
    }
}
因为要代理prometheus面板,加上nginx认证会更加安全
安装 htpasswd 工具
yum -y install httpd-tools
生成用户登录的认证文件
创建文件夹apache2
cd /data
mkdir apache2
创建认证的账号密码
htpasswd -c /data/apache2/.htpasswd ncayu168
路径:/data/apache2/
文件名:.htpasswd
账号:ncayu168
输入密码和确认密码
[root@ncayu618 data]# htpasswd -c /data/apache2/.htpasswd ncayu168
New password: 
Re-type new password: 
Adding password for user ncayu168
查看生成的文件
[root@ncayu618 apache2]# ll -a
总用量 12
drwxr-xr-x 2 root root 4096 10月  8 11:00 .
drwxr-xr-x 6 root root 4096 10月  8 11:00 ..
-rw-r--r-- 1 root root   47 10月  8 11:00 .htpasswd
[root@ncayu618 apache2]# more .htpasswd
ncayu168:$apr1$IiD82C.N$zJLsMYYQHCw0EBDEEJfp3.
配置nginx
#代理prometheus
    location /prometheus {
        proxy_pass http://120.78.85.73:9090/prometheus;
        auth_basic   "Administrator's area";
        auth_basic_user_file /data/apache2/.htpasswd;
     }
重新启动nginx
[root@ncayu618 sbin]# ./nginx -t
nginx: the configuration file /data/applications/nginx1.20.1/conf/nginx.conf syntax is ok
nginx: configuration file /data/applications/nginx1.20.1/conf/nginx.conf test is successful
[root@ncayu618 sbin]# ./nginx -s reload
[root@ncayu618 sbin]# 
图片展示

目前grafana和Prometheus的面板都已经代理出来了

grafana面板代理可以查看这一篇博客https://www.sunofbeach.net/a/1420424098542092289


