启用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