nginx启用status页面并实现nginx的登录账户认证

启用status页面并实现nginx的登录账户认证

开启status页面

1.查看编译安装时所编译的模块
要开启status页面依赖于ngx_http_stub_status_module这个模块

[root@localhost ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

2.修改配置文件开启status页面

[root@localhost ~]# vim /apps/nginx/conf/servers/vs.conf
server {
    server_name www.mylinuxops.com;
    listen 443;
    ssl on;
    ssl_certificate /apps/nginx/certs/www.mylinuxops.com.crt;
    ssl_certificate_key /apps/nginx/certs/www.mylinuxops.com.key;
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:20m;
    location / {
        root /data/www;
        index index.html;
 }
    location /status {
        stub_status;
 }
}

3.测试访问

[root@localhost ~]# curl --cacert /apps/nginx/certs/ca.crt https://www.mylinuxops.com/status
Active connections: 1
server accepts handled requests
 10 10 5
Reading: 0 Writing: 1 Waiting: 0

对status页面进行登录账户认证

1.创建一个用来认证登录的账号

[root@localhost ~]# htpasswd -bcm /apps/nginx/conf/.htpasswd masuri 111111

2.修改配置文件,启用账号认证

[root@localhost ~]# vim /apps/nginx/conf/servers/vs.conf
server {
    server_name www.mylinuxops.com;
    listen 443;
    ssl on;
    ssl_certificate /apps/nginx/certs/www.mylinuxops.com.crt;
    ssl_certificate_key /apps/nginx/certs/www.mylinuxops.com.key;
    ssl_session_timeout 10m;
    ssl_session_cache shared:SSL:20m;
    location / {
        root /data/www;
        index index.html;
 }
    location /status {
        stub_status;
        auth_basic      "login";
        auth_basic_user_file    conf/.htpasswd;

2.检查配置文件,重读配置文件生效

[root@localhost ~]# nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload

3.测试
不使用认证

[root@localhost conf]# curl -k https://www.mylinuxops.com/status
<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>

使用账号密码登录认证

[root@localhost conf]# curl -k -u masuri:111111 https://www.mylinuxops.com/status
Active connections: 1
server accepts handled requests
 23 23 17
Reading: 0 Writing: 1 Waiting: 0

转载于:https://blog.51cto.com/11886307/2403943

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值