• 注册
当前位置:1313e > 默认分类 >正文

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 requests10 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

401 Authorization Required

401 Authorization Required


nginx/1.14.2

使用账号密码登录认证

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

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

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 162202241@qq.com 举报,一经查实,本站将立刻删除。

最新评论

欢迎您发表评论:

请登录之后再进行评论

登录